开发者

Passing Hashtable to Unmanaged code using interop

开发者 https://www.devze.com 2023-01-24 13:11 出处:网络
How can i pas开发者_StackOverflow中文版s HashTable in .net to c++ using interop? I know how to pass primitive types but need to know how can I pass the other ones.You cannot pass the entire object t

How can i pas开发者_StackOverflow中文版s HashTable in .net to c++ using interop?

I know how to pass primitive types but need to know how can I pass the other ones.


You cannot pass the entire object to be used as a hash table in C++. P/invoke translate the .NET type to a type C++ can understand. For example, String is converted to a LPWSTR (wchar_t *). However it cannot convert something like a HashSet in this manner.


You can't.

There is no C++ parameter type to which you can pass a Hashtable (except a void*, which wouldn't do you any good)

Instead, you need to create a C++ struct to hold the information in the hashtable, port the struct to C#, then marshal the struct.

0

精彩评论

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