Communicating from unmanaged C++ to Compact Framework app

  • Thread starter Thread starter Patrick Long
  • Start date Start date
P

Patrick Long

We are building some Today addins which will need to communicate back and
forth with a Compact Framework application.

We are looking at using MessageWindow and windows messages.

This works find but the issue is the discovery of the CF apps message window
handle. I have seen some talk of using FindWindow against the window name
for the MessageWindow form. This does not seem like a good idea as it is
relying on internals of the CF.

Ideas?

TIA

Pat Long
 
How about using registry or some flag file to write the current hWnd of the
MessageWindow?
 
I had thought of a file but thought that a bit poor. I quite like the
registry idea.

Thanks

Pat Long
 
A standard approach will be to register a window message and use it for
handshake:
1) CF app starts and registers a message, e.g.
"MyCompanyMyAppCommunicationMessage"
2) CF app creates MessageWindow-based class that listens to this particular
message (and possibly others).
3) C++ app starts and registers the same message. It calls
SendMessage(HWND_BROADCAST, uMsg, 1, hWnd). Hwnd is the handle of the C++
app window. 1 is a command code CMD_DISCOVER (for instance)
4) CF app receives registered message and sees that the wParam is set to
CMD_DISCOVER. It collects the peer app window handle from lParam.
5) CF app sends a message SendMessage(<handle of the peer app wnd retrieved
in the previous step>, uMsg, 2, hWnd), where hWnd is a handle of CF app
Message Window and 2 is a predefined command CMD_REPLY
6) C++ app receives registered message with wParam set to CMD_REPLY and
retrieves the CF app window handle. Communication is established.

It is better to implement this protocol in a symmetrical manner on both
sides, so that it does not matter which application starts first.
 
Back
Top