Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pointer to memory blocks

0 views
Skip to first unread message

Ray

unread,
Jan 18, 2007, 1:04:02 PM1/18/07
to
Hi

I am trying to transfer data from one application to another by sending a
pointer to a memory block. To test this out I have two applications, a
sender and a receiver. The sender fills an integer buffer and sets a pointer
to its address. Then I send a message via the interop SendMessage();.

I get the message in the Receiver ok and the pointer value received is the
same as the one sent. But when I try to get the data all I get is garbage.

To simplify things both applications are set as an unsafe class;

Send code is

fixed(int* p1=outbuff)
{
SendMessage(recHandle, msg, (IntPtr)(p1),(IntPtr)(p1));
}

Receive code is

protected override void WndProc(ref Message m)
{
if(m.Msg==msg)
{
int* pptr=(int*)m.WParam.ToPointer();
for(int i=0;i<100;i++) richTextBox1.AppendText(i+";
"+(*pptr++).ToString()+"\n");
}
base.WndProc(ref m);
}

Marc Rohloff [TeamB]

unread,
Jan 18, 2007, 2:45:26 PM1/18/07
to
On Thu, 18 Jan 2007 18:04:02 -0000, Ray wrote:

> I am trying to transfer data from one application to another by sending a
> pointer to a memory block. To test this out I have two applications, a
> sender and a receiver. The sender fills an integer buffer and sets a pointer
> to its address. Then I send a message via the interop SendMessage();.
>
> I get the message in the Receiver ok and the pointer value received is the
> same as the one sent. But when I try to get the data all I get is garbage.

You cannot send memory between applications by just sending a pointer.
Each application addresses its own unique memory space and contents.

You need to use one of:
1) TCP/IP
2) Webservices, remoting, etc.
3) Shared memory, Memory Mapped Files, etc
4) The WM_COPYDATA windows message
5) Real files
6) etc


--
Marc Rohloff [TeamB]
marc rohloff -at- myrealbox -dot- com

Ray

unread,
Jan 19, 2007, 1:45:58 PM1/19/07
to
Thanks Marc

Can you point me in the direction of some info on 3) Shared memory, Memory
Mapped Files, etc


Ray
"Marc Rohloff [TeamB]" <"on request"> wrote in message
news:1iwcargj...@dlg.marcrohloff.com...

0 new messages