是否有常见 DLLImport 声明的 C# 版本可用?
有很多 Win32 API 调用/库,例如 kernel32 或 shell32,可用于从 C#。使用它们的常见方法是在 pinvoke.net 网站上查找方法定义,然后使用那里的 dllimport 定义。
您希望使用的每种方法都需要此过程。
是否有包含常见/大多数[DllImport]
ed API 函数的可用程序集?
我正在寻找可以直接从 C# 使用的东西(作为参考),因此我不必自己收集和组合各种 DLLImport 语句(有出错的风险)。
There are many Win32 API calls / libraries like kernel32 or shell32 that may be usefull to call from C#. A common method of using them is looking up the method definition on the pinvoke.net website, and using the dllimport definition from there.
This process is required for every method you wish to use.
Are there assemblies availble that contain common / most [DllImport]
ed API functions?
I'm looking for something i can use directly from C# (as a reference), so i don't have to gather and combine all kinds of DLLImport statements myself (with risk of errors).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该在 pinvoke.net 找到您想要的内容。实际上,C# 源代码中没有什么比简单的 DLL 导入子句更“幕后”的了。
You should find here at pinvoke.net what you are looking for. There's actually nothing more “behind the scenes” that could be shipped in C# source code than plain simple DLL import clauses.
这不是它的工作方式,您只需在 C# 代码中提供 [DllImport] 声明。就像您在 pinvoke.net 或 P/Invoke Interop Assistant 等工具上找到它们一样。了解如何实际使用 API 函数需要学习 C 或 C++ 代码。并大致了解 Windows API 的工作原理。
最好的起点是 Petzold 的开创性著作“Programming Windows”。您可以在 Windows SDK 文档中找到 C/C++ 源代码示例以及完整版 SDK 中包含的许多示例。当然还有网络,只需搜索函数名称即可。具有讽刺意味的是,如今您在网络上找到的用托管语言编写的示例数量开始超过 C/C++ 示例。请注意 VB6 声明(Declare 关键字),它也广泛使用,但其类型与 .NET 不兼容。
像 codeplex.com 和 codeproject.com 这样的网站是查找包含本机 API 调用托管类包装器的库的好地方。您通常只需使用该库即可。
最后但并非最不重要的一点是,stackoverflow.com 是一个极好的资源;)
That's not the way it works, you only provide the [DllImport] declaration in your C# code. Just the way you'd find them on pinvoke.net or a tool like the P/Invoke Interop Assistant. Finding out how to actually use the API function requires studying C or C++ code. And in general understanding how the Windows API works.
The best place to get started with that is Petzold's seminal book "Programming Windows". You can find source code samples in C/C++ in the Windows SDK documentation and the many samples that are included with the full version of the SDK. And the web of course, just by searching for the function name. Somewhat ironically, the number of samples you'd find on the web these days that are written in a managed language start to out-number the C/C++ samples. Beware of VB6 declarations (Declare keyword), also widely available, its types are not compatible with .NET.
Sites like codeplex.com and codeproject.com are a good place to find libraries with managed class wrappers around native API calls. You'd normally simply use the library.
Last but not least, stackoverflow.com is an excellent resource ;)
据我所知,没有众所周知的包装 Windows API for .NET 的代码包;我认为它在某些情况下很有用,但是,在大多数情况下,如果您需要使用如此多的本机 Windows API,那么您可能应该问自己是否正确使用 .NET 框架和/或为什么到底使用.NET吗?
无论上述观点如何,您都可以在 http://pinvoke.net/ 找到相当全面的定义来源。
That I know of, there is no widely known bundle of code wrapping the Windows API for .NET; I could see it being useful in certain circumstances, however, in most cases, if you need to use so much of the native Windows API then you should maybe ask yourself whether or not you're utilising the .NET framework properly and/or why use .NET at all?
Regardless of the above opinion, you can find a pretty comprehensive source of the definitions at http://pinvoke.net/.