David Brown
David Brown

Reputation: 36239

Where can I learn more about P/Invoke?

Lately, I've been doing a lot of interaction with unmanaged libraries and I keep coming back to SO to ask questions about certain method signatures because I'm not a C/C++ programmer (although it's not completely alien to me). There are situations where the same type of argument in two different methods require two different P/Invoke signatures (Ex: sometimes I can use the out keyword, sometimes I have to use OutAttribute, etc). I can't really see any sort of reasoning behind it.

Are there any good resources out there for understanding P/Invoke and marshaling better for someone who isn't a C/C++ expert?

Upvotes: 2

Views: 246

Answers (2)

Hans Passant
Hans Passant

Reputation: 941635

The problem is that the C/C++ languages do not give you a way to see whether the function produces or consumes data and whether an argument pointer points to a single value or an array of values. Learning the languages or studying P/Invoke don't really help with this, although it gives you a better shot at guessing it right.

You can only resolve this is by learning more about the specific native code for which you are writing a P/Invoke declaration. That requires its source code and some familiarity with the language. Or a good working relationship with the code's original author or owner.

Adam Nathan's book is the standard reference.

Upvotes: 3

Adam Maras
Adam Maras

Reputation: 26863

PInvoke.net

Upvotes: 3

Related Questions