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

StackOverflow https://stackoverflow.com/questions/892913

  •  23-08-2019
  •  | 
  •  

Question

I am using setupapi.dll to determine USB device connectivity. It isn't working properly in 64 bit versions of 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. Is there a resource I can use to convert between the function header and the dllimport declaration?

I've used pinvoke.net, but it looks like it doesn't account for 64 bit in the definitions provided.

Was it helpful?

Solution

Check out pinvoke.net. It has a large set of Win32 APIs already translated to DllImport definitions (Including setupapi.dll).

OTHER TIPS

The tool you're looking for is called C++/CLI. It was built to process those headers and generate interop code - no mucking around with P/Invoke.

Write a light-weight wrapper assembly in C++/CLI, and then use it from your C# code.

(Hard to provide a more specific answer, since you didn't really specify how it's not working properly...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top