P/Invoke and null-terminated strings

R

Robert

Hi there,

I have to make a P/Invoke call to "SendMessage()" in the WinAPI, converting
a managed "string" to an unmanaged (C-style, null-terminated) string so I
can pass it via the LPARAM arg. Can someone enlighten me on how to perform
the conversion itself (no assistance needed on invoking "SendMessage()").
Thanks.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Robert said:
I have to make a P/Invoke call to "SendMessage()" in the WinAPI, converting
a managed "string" to an unmanaged (C-style, null-terminated) string so I
can pass it via the LPARAM arg. Can someone enlighten me on how to perform
the conversion itself (no assistance needed on invoking "SendMessage()").

Usually/always (I am not a DllImport guru) the conversion between
string and char* or LPCTSTR are done automatically.

Arne
 
R

Robert

I have to make a P/Invoke call to "SendMessage()" in the WinAPI,
Usually/always (I am not a DllImport guru) the conversion between
string and char* or LPCTSTR are done automatically.

Thanks, but LPARAM is an "IntPtr" so presumably I need to handle the
conversion myself.
 
M

Mattias Sjögren

I have to make a P/Invoke call to "SendMessage()" in the WinAPI,
Thanks, but LPARAM is an "IntPtr" so presumably I need to handle the
conversion myself.

It doesn't have to be an IntPtr, that's just the most general form.
Add another SendMessage overload where lparam is declared as a string
instead, then you can pass in the string argument directly. Just make
sure you use the correct CharSet.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top