Help with managed / unmanaged function

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a VB.Net managed DLL that Im building that is a wrapper for unmanaged code.
I have to pass in a String, convert it to "unsigned char", pass it to another unmanaged function and convert the result to a byte array.
The sister function does the reverse:
<pre class="prettyprint String^ TestClass::TestFunction1(array<System::Byte>^ szByteArray)
{
Widget * oWidget = new Widget();
String ^sPassword = "";
UINT8 szPasswordDest[8] = {};
pin_ptr<System::Byte> p = &szByteArray[0];
oWidget->func1(szPasswordDest, p, sizeof(szByteArray), m_key);
sPassword = Marshal::PtrToStringAnsi((IntPtr)szPasswordDest, (sizeof(szByteArray) * 2));
Marshal::FreeBSTR((IntPtr)p);
return sPassword;
}[/code]
Assuming that oWidget->func2 takes the same parameters, I have not been able to get it to work. I need to pass in a string and then convert it to UINT8 (typedefined as unsigned char), run func2 and convert the resulting szPasswordDest to a byte
array.



<hr class="sig Steve

View the full article
 
Back
Top