Home All Groups Group Topic Archive Search About

Copy data between processes

Author
22 Feb 2006 8:35 AM
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.

Author
22 Feb 2006 9:05 AM
Vadym Stetsyak
Hello, Tomer!

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

T> This is the code I'm using:

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

To transfer data in this way you have to use WM_COPYDATA windows message.
( http://www.codeproject.com/csharp/wm_copydata_use.asp )
( http://www.codeguru.com/Cpp/W-P/win32/article.php/c1429 )

Another way that you can use for IPC can be:
-sockets
-memory-mapped files
-named pipes
-remoting

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Author
22 Feb 2006 9:17 AM
Vadym Stetsyak
Forgot to add one more url on WM_COPYDATA
( http://www.gotdotnet.com/Community/MessageBoard/Thread.aspx?id=208779 )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

AddThis Social Bookmark Button