Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems using CreateProcesas and WaitForSingleObject 1

Status
Not open for further replies.

doberkofler

Programmer
Oct 10, 2001
3
AT
hi to all!

i have some major problems when using the CreateProcess win32 api function in conjunction with the WaitForSingleObject wi32 api fuction waiting for the spwned process to terminate.

we are using the CreateProcess function to open a word document with the micrsoft WinWord aplication and everything runs fine as long as WinWord was not already running when calling CreateProcess. if WinWord was already running, the call to CreateProcess simply changes the currently visible document in the WiNWord application and WaitForSingleObject immediately returnd as if the application would have been terminated.

is there a way to force CreateProcess to create a "new" process or what lese might go wrong here.

thank you for your help

do
 
Yes, Word is an COM server and the rules there are a little different. You can force a new process to start by setting dwCreationFlags to CREATE_NEW_PROCESS_GROUP (this is no doubt not the intended use of this flag) but it won't I suspect change the result of WaitForSingleObject() (I'm guessing here...)

It's probably better to use COM functions to start word and check for document closed. :) Hope that this helped! ;-)
 
thank you for your quick feedback.

in fact using com functionality would probably solve most of my problem (there are some more) but also would only work with application sthat support com in a predefined way. the app we are working on is supposed to be able to view any document registered by it's extension by calling the appropriate application and this eems only (reasonably) possiblr by using the CreateProcess api.
how would you else try to solve this typical "document viewer" problem ?

thank you once again for your feedback
 
Actually after a couple more tests (this problem is sort of interesting) I think my previous comment was incorrect anyway. Comes from running quick tests after working all day...it seems to me that using ShellExecuteEx() would be a simpler approach to starting apps since it finds the correct app without the need to look in the registry. ShellEecuteEx() works a bit differently to CreateProcess(), returning the app instance and no hprocess if the app was already running. At least, that's what seemed to be happening in my current state of tiredness:)

It's not clear to me why you need to wait for the app to finish to provide a viewer, however you should be able to see if your document is open for a (well behaved) COM app by looking in the running object table, not that that is completely trivial.

:) Hope that this helped! ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top