I know how to PInvoke a method that wants a CString by using LPCTSTR instead and setting up the DllImport to call with the LPstr conversion.
However, how would I do it with SendMessage where LPARAM is an IntPtr?
Would this work?
[DllImport("user32.dll", CharSet = CharSet.Ansi)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam,
[MarshalAs(UnmanagedType.LPStr)] String lParam);
You can declare it simply like this:
The default marshalling is as an pointer to null-terminated character array. If you really want the ANSI version, then that’s the default. And you should use
SetLastErrorin case you want to capture the error code in case of failure.I trust you know that it cannot work if the window is in a different process.