Is it possible to poke a process created by createprocess?

I have a program that uses createprocess to open another program (in a different thread). Is there a simple way to send a message to that process from my program that I can handle in the WM message loop of my other program? I only need to send 1 type of message when a shared file is updated.

How can I do that?
Use RegisterWindowMessage() to register a user-defined message, and then process this user-defined message in your top level window procedure.
So I have 2 programs, let's call em main and alt for now.

Ok, so I've tried looking into this and if I understand it correctly I need to call
poke = RegisterWindowMessage(L"Monocle_poke");
in both programs. I load the second program using:

bool open, DWORD idthread and uint poke are all globals in main.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
DWORD WINAPI ThreadProc( LPVOID lpParameter)
{
    if(!open){
        open = true;
        STARTUPINFO          si = { sizeof(si) };
        PROCESS_INFORMATION  pi;
        char * cstr, *p;

        wstring str = (L"alt.exe");

        if(CreateProcess(0, &str[0], 0, 0, FALSE, 0, 0, 0, &si, &pi))
        {
        // optionally wait for process to finish
        WaitForSingleObject(pi.hProcess, INFINITE);


        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
        open = false;
        }
}

return 0;
}

which is called from another function that has
1
2
3
4
5
6
7
8
9
    if(open){
    PostThreadMessage(
                idthread,
                poke,
                wp,
                lp
              );
    } else
    CreateThread(0, 0, ThreadProc, 0, 0, &idthread);


in my message handler in alt, I check if the message == poke, and that is never the case.

I also tried to send WM_CLOSE but that doesn't work either.
What am I doing wrong? and if I'm doing something entirely too complicated for my own good, can I send one of the standard messages (like WM_LBUTTON_UP, which does almost exactly what I want poke to do) instead? and how?
Last edited on
Where do you get the value for the argument 'idthread' in the second piece of code, line 3? Because It would have to be the thread ID of the OTHER executable. Pretty much the thread the ID returned by CreateProcess().
I added idthread = pi.dwProcessId; below line 12 in the first one and changed &idthread in line 9 of the second one to some new variable. It still doesn't work.
What is the return value of PostThreadMessage()? If it is FALSE, then call GetLastError() and FormatMessage() to obtain the error number and the error message.
It gave me invalid thread identifier, which is right because idthread should be pi.dwThreadID instead so I fixed that. I managed to send WM_QUIT across, which is a big victory. However, my poke message still didn't get through, neither did my attempt to send WM_LBUTTONUP or WM_DESTROY or any other message that I actually handle...
If you are getting TRUE out of the API call, 2 more questions:

1. Where are you expecting this message? It cannot be in a window procedure because it is not directed to a window, so it must be processed directly in the message pump.
2. What are wp and lp? Windows will not marshal memory, so if those are pointers, that doesn't work. You need to marshal the memory yourself or use the standard WM_COPYDATA message.
Your first point was the problem, thanks.

wp and lp were just a WPARAM and an LPARAM, works fine.
Topic archived. No new replies allowed.