Send a struct to external DLL
-
Hi All I have a project in C# that I need to import C++ dll In order to import it I’m using [DllImport("CommunicationManagerDLL.dll")] private static extern bool WiMAXGetState(ref eNDIS_802_16E_STATE NDIS_802_16E_STATE); how can I send a pointer to struct to the dll ? should I use ref? Thanks Ronen
-
Hi All I have a project in C# that I need to import C++ dll In order to import it I’m using [DllImport("CommunicationManagerDLL.dll")] private static extern bool WiMAXGetState(ref eNDIS_802_16E_STATE NDIS_802_16E_STATE); how can I send a pointer to struct to the dll ? should I use ref? Thanks Ronen
This should work if you're struct is correct.
eNDIS_802_16E_STATE NDIS_802_16E_STATE interopStruct = new eNDIS_802_16E_STATE NDIS_802_16E_STATE();
bool result = WiMAXGetState(ref interopStruct);Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
This should work if you're struct is correct.
eNDIS_802_16E_STATE NDIS_802_16E_STATE interopStruct = new eNDIS_802_16E_STATE NDIS_802_16E_STATE();
bool result = WiMAXGetState(ref interopStruct);Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)That looks fine for simple structs, holding value types only, except maybe for padding and different semantics (long and char). And it could go terribly wrong when the struct holds reference types or pointers. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
That looks fine for simple structs, holding value types only, except maybe for padding and different semantics (long and char). And it could go terribly wrong when the struct holds reference types or pointers. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
Of course, with no info on the struct it's impossible to be absolutly sure!
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)