简体   繁体   English

在哪里可以找到解释如何获取C / C ++函数标头并在C#中使用dllimport对其进行定义的参考?

[英]Where can I find a reference explaining how to take a C/C++ function header and define it with dllimport in C#?

I am using setupapi.dll to determine USB device connectivity. 我正在使用setupapi.dll来确定USB设备连接。 It isn't working properly in 64 bit versions of windows (XP, Vista). 在64位版本的Windows(XP,Vista)中无法正常工作。 I suspect that the declarations are not quite correct, but am not sure how to verify. 我怀疑声明不是很正确,但是不确定如何验证。 MS doesn't seem to provide the dllimport information, but they do list all the function definitions. MS似乎没有提供dllimport信息,但它们确实列出了所有函数定义。 Is there a resource I can use to convert between the function header and the dllimport declaration? 有没有可以在函数头和dllimport声明之间转换的资源?

I've used pinvoke.net, but it looks like it doesn't account for 64 bit in the definitions provided. 我使用过pinvoke.net,但看起来它不占所提供定义中的64位。

The tool you're looking for is called C++/CLI. 您正在寻找的工具称为C ++ / CLI。 It was built to process those headers and generate interop code - no mucking around with P/Invoke. 它是为处理这些标头并生成互操作代码而构建的 -不会与P / Invoke产生冲突。

Write a light-weight wrapper assembly in C++/CLI, and then use it from your C# code. 用C ++ / CLI编写一个轻量级的包装程序集,然后从您的C#代码中使用它。

(Hard to provide a more specific answer, since you didn't really specify how it's not working properly...) (硬盘提供了更明确的答案,因为你并没有真正说明它是如何工作不正常...)

Check out pinvoke.net . 查看pinvoke.net It has a large set of Win32 APIs already translated to DllImport definitions (Including setupapi.dll). 它具有大量Win32 API,它们已经转换为DllImport定义(包括setupapi.dll)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM