On Sat, 29 Sep 2007 14:33:06 -0400, "Scott McPhillips [MVP]"
<org-dot-mvps-at-scottmcp> wrote:
"Paco" <paco_beams@gmail.com> wrote in message
news:UbwLi.1053$ua4.736@newssvr22.news.prodigy.net...
I have a program that receives data from a serial port. No transmit. I
want
to build a separate program that will run on the same PC that also needs
to
receive the same serial port data. No transmit.
I figured one program would pass data to the other program. I could use
a
TCP socket to localhost. This would be easy. Is there a better way?
Nothing wrong with using a socket, but this simple approach can send a
data
array to the main window of another program.
CWnd* p = CWnd::FindWindow(...);
p->SendMessage(WM_COPYDATA, ...);
...and the receiving program would use
ON_MESSAGE(WM_COPYDATA, OnCopyData)
It works fine, but I remember Joseph Newcomer having comments about
this. You want to target the WM_COPYDATA message to the specific
window. Here is what we wrote back in 2005:
"The way I find the target process (one of many ways) is to broadcast
a Registered WIndow Message saying "Here I am", which contains the
HWND in one of the [WL]PARAMs. Only the other process recognizes this.
It then sends back to that HWND a message "I see you are there",
contianing its HWND in [WL]PARAM. Now the communication is
established."
"I gave up using FindWIndow years ago. Too dangerous. For example,
when our German distributor internationalizes the app, the caption
will change in ways I cannot predict, and I don't want to put the
burden on him of making sure that the STRINGTABLE entry in one program
is identical to some STRINGTABLE entry in the other program."
I find Joe's comments especially helpful -- that is why I saved this
from several years ago!