You are trying to do dirty business, communication between different processes in the outlaw Windows-specific way. Processes are well isolated, and communication via messages is Windows perverted style which was rendered obsolete since the introduction of NT, but supported ever since.
What you are trying cannot work because you do it in non-Unicode way. First of all, the foreign application you are trying to send message to should be compiled to support Unicode, which may or may not be the case; if not, nothing will work. Secondly, you should use "wide" form of
SendMessage
and marshal the string accordingly. Try this:
using System.Runtime.InteropServices;
const string DllName = "User32.dll";
[DllImport(DllName, EntryPoint="SendMessageW")]
static extern void SendMessage(IntPtr windowHandle, UInt32 message, UInt32 wParam, [MarshalAs(UnmanagedType.LPWStr)] string message);
The numeric types should depend on the target platform. If I'm not much mistaken, all numeric parameters becomes
Uint64
on 64-bit instruction-set architectures.
Please try — I did not test it. Anyway, you got the idea.
—SA