Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Hashtable to Unmanaged code using interop

Tags:

c#

.net

interop

How can i pass 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.


2 Answers

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.

like image 143
Pieter van Ginkel Avatar answered Feb 17 '26 14:02

Pieter van Ginkel


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.

like image 31
SLaks Avatar answered Feb 17 '26 16:02

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!