I need to wrap an unmanaged function with pinvoke in my C# program.
Is there any way I can know whether or not my managed declaration in C# matches the native one?
I noticed that if it doesn't match, when I try to call it no execption is thrown so I can't know if the function was really called.
(The unmanaged function is from a 3rd party component so I can't put in it logs or change it.)
There's no way to automatically check that your p/invoke declaration matches the native function. The onus is on you to get it right.
Often if you get it wrong an exception will be raised. But not always.
Occasionally I have replicated a complex function signature in my own unmanaged DLL and tested that to learn exactly how arguments are marshaled by P/Invoke. You can then debug from the managed code into the unmanaged code if you enable unmanaged debugging in your managed project and this can assist you in troubleshooting why P/Invoke fails.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.