locked
Sending Messages between two apps RRS feed

  • Question

  • Hello,

    I've been working for some time now on sending messages between two apps written in Visual Studio 2005 C++. It's been a long and difficult struggle, and I've had to range all over the internet to get where I am right now. Anyway, my learning would probably go a lot faster if I could get my hands on an example. Does anyone have a VERY basic example of some code that gets two windows to send messages back in forth with SendMessage()? Or maybe you can point me to the right post/thread/website?  Right now, the files I'm including are "windows.h" (winuser.h wouldn't compile, but someone posted windows.h includes that file anyway), and my call of SendMessage() looks like this:

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    LPCWSTR MyName = reinterpret_cast<LPCWSTR>("ReceivingWindow");
    HWND hwndExternalApplication;
    hwndExternalApplication = FindWindow(NULL, MyName);
    SendMessage(hwndExternalApplication,WM_COPYDATA,NULL,NULL);
    }

    I used reinterpret_cast, because the compiler wouldn't convert the string "Receiving Window" to LPCWSTR. I don't know if this is right or not. Right now the error I'm working on is that the compiler says SendMessage() does not take 4 parameters. However, all of the documentation, and the intellisense, say otherwise.

    Any help would be greatly appreciated...but a code sample would make you my hero!

    Thank you,
    BWilhite

    Edit:  Just wanted to note I found the FAQ that addressed the string conversion issue:  The reinterpret_cast has been removed.  Now the FindWindow() call looks like this:

    hwndExternalApplication = FindWindow(NULL, L"ReceivingWindow");


    Wednesday, December 27, 2006 11:46 AM

Answers

  • I moved from trying to use the WinAPI to Remoting technology.  That is much easier :)
    Monday, January 1, 2007 2:16 PM

All replies

  •  Bwilhite wrote:
    Right now the error I'm working on is that the compiler says SendMessage() does not take 4 parameters. However, all of the documentation, and the intellisense, say otherwise.
    I am surprised that intellisense says that SendMessage takes 4 parameters if the compiler says it does not. As for the documentation, you might be looking at the wrong documentation. SendMessage takes 4 parameters for the (global) API call, but you might be using a member function and/or namespace version of SendMessage. I am not familiar with the CLR (.Net?) but if there is a SendMessage in the System namespace then look at the documentation of it.
    Wednesday, December 27, 2006 4:10 PM
  • I moved from trying to use the WinAPI to Remoting technology.  That is much easier :)
    Monday, January 1, 2007 2:16 PM