I just tried this code and it worked ok. Try this on your system and see what you get. Maybe there is a global option that causes it
to marshal as unicode or maybe it thinks your function is unicode because it doesn't end in a capital A. Try using
CharSet=CharSet.Ansi
[DllImport("user32", EntryPoint= "MessageBoxA")]
private static extern int MessageBoxAPI(IntPtr hwnd, string lpText, string lpCaption, int wType);
string x = "This is a test!";
string y = "Test caption!";
MessageBoxAPI(this.Handle, x, y, 0);
--
Michael Culley
"jim" <ji**@kc.rr.com> wrote in message news:0f****************************@phx.gbl...
I have read that the string will marshal over to a char*
but for some reason it didn't owrk for me.
here is my DllImport code
[DllImport("PikaAPI.dll")]
public static extern uint PK_VP_PlayDTMFString(uint
BoardPort, string PK_PCHAR);
then I call it using
string x = textBox1.text;
PK_VP_PlayDTMFString(hPort, x);
but not luck. any ideas?
-----Original Message-----
"Jim" <ji**@kc.rr.com> wrote in message
news:07****************************@phx.gbl... I have to access a third party api to work with their
hardware. Everything was going great UNTIL I ran into the problem of C# char being 16 bits and the C char being 8
bits. I cannot seem to cast the string properly to use it in the unmanaged code.
You shouldn't have to do anything, it should just marshal
accross as an 8 bit null terminated char* that will work
in C. eg
[DllImport("user32", EntryPoint= "MessageBoxA")]
private static extern int MessageBox(IntPtr hwnd, String
lpText, String lpCaption, int wType);
--
Michael Culley
"Jim" <ji**@kc.rr.com> wrote in message
news:07****************************@phx.gbl... I have to access a third party api to work with their
hardware. Everything was going great UNTIL I ran into the problem of C# char being 16 bits and the C char being 8
bits. I cannot seem to cast the string properly to use it in the unmanaged code.
I have tried to use the MarshalAs function in my DllImport statement but that didn't work.
What i need is to take a string of numbers and convert it to a Zero Terminated C string or char. Can anyone please help me.
.