Jump to content

Recommended Posts

Posted

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, .)

 

 

More...

 

View All Our Microsoft Related Feeds

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...