Use CreateProcess And send WM_COPYDATA message

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?

thnx
swapnil001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RichieHindleCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
swapnil001Author Commented:
Thanks Richie, it works !! :)
0
RichieHindleCommented:
Happy to help!  8-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.