在哪里可以了解有关 P/Invoke 的更多信息?
最近,我一直在与非托管库进行大量交互,并且我不断回到 SO 询问有关某些方法签名的问题,因为我不是 C/C++ 程序员(尽管这对我来说并不完全陌生)。在某些情况下,两个不同方法中的相同类型的参数需要两个不同的 P/Invoke 签名(例如:有时我可以使用 out
关键字,有时我必须使用 OutAttribute
等)。我真的看不出其背后有任何推理。
对于不是 C/C++ 专家的人来说,是否有任何好的资源可以帮助他们更好地理解 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 C/C++ 语言没有提供一种方法来查看函数是否生成或消耗数据以及参数指针是否指向单个值或值数组。学习语言或研究 P/Invoke 对此并没有真正的帮助,尽管它可以让您更好地猜测它。
您只能通过了解有关您为其编写 P/Invoke 声明的特定本机代码的更多信息来解决此问题。这需要它的源代码和对该语言的一定程度的熟悉。或者与代码的原始作者或所有者有良好的工作关系。
Adam Nathan 的书是标准参考。
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.
PInvoke.net
PInvoke.net