EDN Admin
Well-known member
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:trToStringAnsi((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
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:trToStringAnsi((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