开发者

What are best practices for using IntPtr vs. void* in C++/CLI?

开发者 https://www.devze.com 2023-03-02 04:44 出处:网络
I\'m using it for passing native pointers between assemblies. It\'s unfortunate that strong typing goes out the window in that context. Or at least, I haven\'t figured out how to get cross-assembly ac

I'm using it for passing native pointers between assemblies. It's unfortunate that strong typing goes out the window in that context. Or at least, I haven't figured out how to get cross-assembly access to a C++/CLI method that returns a pointer to 开发者_运维知识库a native UDT. So assuming I'm right that either IntPtr or void* is necessary here, which should I use?


Always prefer the CLS-compliant route, in this case IntPtr. Not all .NET languages know what void* is, but all know what IntPtr is.

Regarding cross-assembly use of native UDTs, see #pragma make_public.

0

精彩评论

暂无评论...
验证码 换一张
取 消