Use CreateProcess And send WM_COPYDATA message

Posted on 2004-11-05
Medium Priority
Last Modified: 2013-11-13
Hi ,
I have a process A to which i need to send WM_COPYDATA messages thru windows SendMessageTimeout api.
I first check whether the process is already running. If not, it first starts the process A.
I am using CreateProcess windows api to create the process. after the process is created i send a WM_COPYDATA message to the process. To get the handle of the process once it is created i tried following methods:

1) Get the handle from the ProxessInformation structure (pi) passed to the CreateProcess method as it contains the proxess handle once the process is created.

pOtherWnd = (HWND)pi.hProcess;

2) Get the handle of the process by using windows FindWindow api.

The problem is that the first time after the process is created, the OnCopyData() method in the process A is not getting called. From next time on (i.e. when the process A is found to be running already and no CreateProcess is called) the OnCopyData() method is called successfully.

Any ideas?

Question by:swapnil001
  • 2
LVL 14

Accepted Solution

RichieHindle earned 600 total points
ID: 12509686
Try calling WaitForInputIdle() between CreateProcess() and FindWindow().

"The WaitForInputIdle function enables a thread to suspend its execution until the specified process has finished its initialization and is waiting for user input with no input pending. This can be useful for synchronizing a parent process and a newly created child process."

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitforinputidle.asp for full details.

Author Comment

ID: 12510322
Thanks Richie, it works !! :)
LVL 14

Expert Comment

ID: 12512223
Happy to help!  8-)

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question