Sending a message to parent from child process

This is a discussion on Sending a message to parent from child process within the C++ Programming forums, part of the General Programming Boards category; I want my child process (created with createprocess) to send a message to my parent process. Parent process is using ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Sending a message to parent from child process

    I want my child process (created with createprocess) to send a message to my parent process. Parent process is using a window so I would want my child process to get the handle of the parent process and then use something like sendmessage to parent process...

  2. #2
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    If i remember correctly. createprocess has a method of returning the address of the new process.
    You pass it a struct pointer to a struct PROCESS_INFORMATION
    then read the info in that struct to get the handle of the process so you can send your message.



    parameter of the createprocess()

    pProcessInformation
    [out] Pointer to a PROCESS_INFORMATION structure that receives identification information about the new process.

    Handles in PROCESS_INFORMATION must be closed with CloseHandle when they are no longer needed.


    Some relevant links..
    http://msdn.microsoft.com/library/de...ateprocess.asp
    http://msdn.microsoft.com/library/de...mation_str.asp

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Example code that was made very shortly ago:

    Code:
    #include <windows.h>
    BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
    {
    	DWORD processId;
    	GetWindowThreadProcessId(hwnd, &processId);
    
    
    	if(lParam == processId)
    		PostMessage(hwnd, WM_YOURMESSAGE, 0, 0);
    	return TRUE;
    }
    int main(int argc, char *argv[]) {
    	STARTUPINFO         siInfo;
    	PROCESS_INFORMATION piInfo;
    
    	ZeroMemory(&siInfo, sizeof(siInfo));
    	ZeroMemory(&piInfo, sizeof(piInfo));
    
    	CreateProcess
    		("C:\\WINDOWS\\Notepad.exe", "", 0, 0, 
    		FALSE, CREATE_DEFAULT_ERROR_MODE, 0, 0, 
    		&siInfo, &piInfo);
    
    	WaitForSingleObject(piInfo.hProcess, 1000);
    	EnumWindows(&EnumWindowsProc, piInfo.dwProcessId);
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 08:38 PM
  2. inter process communcation, parent - child
    By tallan in forum C Programming
    Replies: 5
    Last Post: 02-28-2009, 04:04 AM
  3. create a child process that creates a child process
    By cus in forum Linux Programming
    Replies: 9
    Last Post: 01-13-2009, 02:14 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21