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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WaitForSingleObject stopped working

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
I'm using some code to launch Word and wait until the user closes it. The code has worked fine for years but for some reason has now stopped working, I'm wondering if either Windows or Office has had some kind of update that would have affected it?
Code:
Const Synchronize = &H100000
Private Const Infinite = -1&
lRetVal = Shell(WordApp$, vbMaximizedFocus)
ShellAndHold = OpenProcess(Synchronize, False, lRetVal)
lRetVal = WaitForSingleObject(ShellAndHold, Infinite)
lRetVal = CloseHandle(ShellAndHold)

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
OK I have some new information on this problem and it might help you to replicate what is happening.

I restarted my machine and tried my code and it worked fine, WaitForSingleObject sat there waiting for Word to close. If I then run it again several times it works every time. After Word closes there is no mention of WINWORD.EXE in the Processes list in Task Manager.

However...

If I open Outlook 2003 and minimise it and then try my code it doesn't work. I've also noticed that with Outlook open there is no splash screen as Word opens, it's just there immediately. Checking the Processes list shows that WINWORD.EXE is still running even if Word is not open.

If I then close Outlook and try the code again Word still opens immediately and the code does not work. Only when I terminate OUTLOOK.EXE from the Processes list does it start working again.

Now I guess that Outlook 2003 uses Word as the email composition editor (I don't use Outlook so I'm not sure about that), and so it must be keeping Word running as a process so that it opens immediately when you want to compose a new email, but the weird thing as far as I'm concerned is that even if you terminate WINWORD.EXE it still opens immediately - but I guess Word and Outlook share enough DLLs that the load time is negligable. I'm not sure why WaitForSingleObject doesn't work when there is no WINWORD.EXE process in the list though...

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
>I guess that Outlook 2003 uses Word as the email composition editor

Indeed it can do.
 
Hi,

I've noticed in the past that the Winword process is still in the taskmanager for some time after the application is closed.

It caused me a minor problem not so long ago as I changed normal.dot, saved it as doc1.dot and then tried to rename normal.dot to .bak but kept getting an error message saying it was in use.

Once I'd stopped the Winword process it allowed me to rename the files.

Regards
Peter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top