访问 Microsoft.Win32.UnsafeNativeMethods?

发布于 2024-08-19 21:58:55 字数 254 浏览 3 评论 0原文

Microsoft 在 .NET 框架中包含了一个非常好的 Windows API 包装器。它存储在 Microsoft.Win32.UnsafeNativeMethodsMicrosoft.Win32.SafeNativeMethodsMicrosoft.Win32.NativeMethods 中。不幸的是,它们无法访问,因为它们被声明为私有。有没有一种方法可以轻松访问它们?

Microsoft has a very nice Windows API wrapper included in .NET framework. It is stored in Microsoft.Win32.UnsafeNativeMethods , Microsoft.Win32.SafeNativeMethods and Microsoft.Win32.NativeMethods.Unfortunately they aren't accessible because they are declared as private. Is there a way of accessing them easily?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小梨窩很甜 2024-08-26 21:58:55

这些类中的大多数方法定义(如果不是全部)都是带有 DllImport 属性,通过 P/Invoke 引用 Windows API 中的函数。这些声明位于何处并不重要。您可以创建自己的名为 UnsafeNativeMethods 或 SafeNativeMethods 的类,并在其中放置引用相同 Windows API 函数的声明。您可以在 pinvoke.net 上找到许多适用于 C# 的 Windows API 函数的签名。

Most method definitions in those classes (if not all) are extern declarations with DllImport attributes that refer to functions in the Windows API through P/Invoke. In doesn't matter where these declarations reside. You can create your own class named UnsafeNativeMethods or SafeNativeMethods and put declarations referring to the same Windows API functions in there. You'll find the signatures of many Windows API functions for C# on pinvoke.net.

誰認得朕 2024-08-26 21:58:55

对于它的价值,我一直认为应该有一个 kernel32.interop.dll 等,其静态方法已经 DllImport'ed。但我已经根据需要创建了自己的。多年来,我发现我很少使用其中的几个以上,但是当我需要一个尚未导入的 API 时,这真是太痛苦了。

For what it's worth I always thought there should have been a kernel32.interop.dll etc with the static methods already DllImport'ed. But I've resorted to creating my own on an as-needed basis. Over the years I've found I rarely use more than a handful of them but it's such a pain in the ass when I need an API that I haven't imported yet.

和我恋爱吧 2024-08-26 21:58:55

这些类中包含的大部分功能都是由 .Net 框架本身公开的;您应该在进行 API 调用之前进行搜索(或在此处询问)。

回答你的问题,不。
您能做的最好的事情就是从 Reflector 或参考源复制它们。

Most of the functionality contained in these classes is exposed by the .Net framework itself; you should search (or ask here) before making API calls.

To answer your question, no.
The best you can do is to copy them from Reflector or the reference source.

呢古 2024-08-26 21:58:55

原因可能是 SuppressUnmanagedCodeSecurityAttribute 的安全影响。检查将 P/Invokes 移至 NativeMethods 类

The reason could be the security impact of SuppressUnmanagedCodeSecurityAttribute. Check Move P/Invokes to NativeMethods class

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文