Copy data between processes

  • Thread starter Thread starter Tomer
  • Start date Start date
T

Tomer

Hi,

I'm using the PostMessage method to send a message to another application.
I also wish to send a string with that message, and recieve it in the other application.
Using the Marshal.PtrToStringUni doesn't work,on the recieving application, and results an exception (I suspect that it doesn't work onther different processes)

This is the code I'm using:

Sending application:
Message msg = Message.Create(otherApplicationWindowHandle, WM_TAKE_SNAP_SHOT, IntPtr.Zero, StringUniIntPtr(stringName));
MessageWindow.PostMessage(ref msg);

private static IntPtr StringUniIntPtr(string str)
{
if(str == null)
return IntPtr.Zero;
int i = (str.Length + 1) * System.Text.UnicodeEncoding.CharSize;
IntPtr ptr = Core.LocalAlloc(Core.LPTR,(uint)i);
byte[] data = Encoding.Unicode.GetBytes(str);
Marshal.Copy(data, 0, ptr, data.Length);
return ptr;
}
Recieving application:

string[] msgParams = {Marshal.PtrToStringUni(message.LParam)};
Core.LocalFree(message.LParam);

I've also tried using the API function RtlMoveMemory but it is not supprted in the CE.

Any suggestions?

Thanks, Tomer.
 
Back
Top