If I call the native DLL like this:
string dfhgfdgh = "jhdgjhdjghjdtgyhn";
[DllImport("StringTestNativeDLL", CallingConvention = CallingConvention.Winapi)]
public static extern byte GetVehicleIdentification(ref string vehicleIdentification);
private void button1_Click(object sender, EventArgs e)
{
GetVehicleIdentification(ref dfhgfdgh);
textBox1.Text = dfhgfdgh;
}
and the native DLL looks like this:
char m_VehicleIdentification[200];
extern "C" __declspec(dllexport) BYTE __stdcall GetVehicleIdentification(wchar_t** vehicleIdentification)
{
strcpy(m_VehicleIdentification, "1234567890");
strcpy (*vehicleIdentification, m_VehicleIdentification);
return 0;
}
The text in my textbox is a sequence of squares equal to half the number of characters in the string above i.o.w. 5 squares (unrecognized characters)
It seems like it’s trying to interpret the ascii-string as a unicode string (2 bytes per character). If I try to
public static extern byte GetVehicleIdentification([MarshalAs(UnmanagedType.LPStr)]ref string vehicleIdentification);
I get a “Not supported”-exception. I get the same result for LPTStr LPWStr BStr BTStr and all other string types which I have tried.
Is it not possible in the Compact Framework to call a native function which has a char** in-parameter and get a valid string back in any other way than to work with wchar_t** in the native function? I don’t want to use unsafe C#-code. (If cut the ref and use char* instead in the native function I get the same result, □□□□□□□□□□□□□.)
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.