Board index » delphi » Communicating between two programs

Communicating between two programs

How shall I do to communicate between two applications?

I want one application to store several big bitmaps, and many instances of
the other application to run at the same time sharing the bitmaps.

What I want to do is to recive a pointer to one of the bitmaps

 this is how I do:

{First i find the other window}
AHandle := FindWindow(nil, PChar('TheWindow'));

{Then I Register the Message}
GETBITMAP_MESSAGE := RegisterWindowsMessage('GETBITMAP_MESSAGE');

{Next I Sends the Message and Recives a pointer}
ThePointer :=  Pointer(SendMessage(AHandle, GETBITMAP_MESSAGE,
Integer(BitmapId), 0));

BitmapId is a string
ThePointer is a pointer to the bitmap i want to use.

I override the WndProc In the other application to catch the message, that
works but the string in WParam points to trash memory

What am i doing wrong?

Regards David

 

Re:Communicating between two programs


You must create a Global Memory page to pass string information to another
application since all applications have their own virtural memory and there
for one
can not do anything with the other!!.
  how ever, of you create a global memory chuck and load the string
information
into that, you pass that to the main program, the main program thus will pass
back
a handle to the pointer..
   bare in mind that you may not be able to access the image via the pointer
passed
back to you because the it may belong to the main app and thus be a virtual
pointer..
 in which case you may need to create a another global page of memory and
load the whole contents of the image in that page and thus pass back the
handle
to the memory, when completed you free the handle.
  if you take the image in the main program and set the pixel format to
something
other then the default value then the bit image will thus be loaded into user
memory
and by using the Scanline property you may be able to pass back the pointer to
that
memory with out to much problem..
Quote
"David Br?nnvall" wrote:
> How shall I do to communicate between two applications?

> I want one application to store several big bitmaps, and many instances of
> the other application to run at the same time sharing the bitmaps.

> What I want to do is to recive a pointer to one of the bitmaps

>  this is how I do:

> {First i find the other window}
> AHandle := FindWindow(nil, PChar('TheWindow'));

> {Then I Register the Message}
> GETBITMAP_MESSAGE := RegisterWindowsMessage('GETBITMAP_MESSAGE');

> {Next I Sends the Message and Recives a pointer}
> ThePointer :=  Pointer(SendMessage(AHandle, GETBITMAP_MESSAGE,
> Integer(BitmapId), 0));

> BitmapId is a string
> ThePointer is a pointer to the bitmap i want to use.

> I override the WndProc In the other application to catch the message, that
> works but the string in WParam points to trash memory

> What am i doing wrong?

> Regards David

Other Threads