Use CreateProcess And send WM_COPYDATA message

Posted on 2004-11-05
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
    LVL 14

    Accepted Solution

    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 for full details.

    Author Comment

    Thanks Richie, it works !! :)
    LVL 14

    Expert Comment

    Happy to help!  8-)

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Join & Write a Comment

    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now