Article View: borland.public.csharpbuilder.language.csharp
Article #113Pointer to memory blocks
From: Ray
Date: Thu, 18 Jan 2007 18:04
Date: Thu, 18 Jan 2007 18:04
31 lines
1763 bytes
1763 bytes
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);
}
Technical Details
Message-ID:
<45afb662@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,661707b8138e8efd,start X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Ray" <noreply@daemon.com> Newsgroups: borland.public.csharpbuilder.language.csharp Subject: Pointer to memory blocks Date: Thu, 18 Jan 2007 18:04:02 -0000 Lines: 34 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 NNTP-Posting-Host: 81.76.231.144 Message-ID: <45afb662@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1169143394 81.76.231.144 (18 Jan 2007 10:03:14 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail