How to get the string passed by SendMessage?

G

Guest

1. I am using SendMessage (HWND_BROADCAST, WM_FONTCHANGE, 0,
(LPARAM)pFileName); in C++ side
2. In WndProc, I wanted to get the fileName from m.lparam, which is a
IntPtr. How can I convert it to a string in C#

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

Gary,

You can pass this to the IntPtr to the static PtrToStringAnsi or
PtrToStringUni methods on the Marshal class depending on what version of
SendMessage was called (SendMessageA, or SendMessageW).

Hope this helps.
 
G

Goran Sliskovic

Gary said:
1. I am using SendMessage (HWND_BROADCAST, WM_FONTCHANGE, 0,
(LPARAM)pFileName); in C++ side
2. In WndProc, I wanted to get the fileName from m.lparam, which is a
IntPtr. How can I convert it to a string in C#

Thanks.

I'm not sure that pointer is valid in other applications/processes
(other than one that call SendMessage). Check WM_COPYDATA if you need IPC.

Regards,
Goran
 

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