Hello all! Here is some "strange" behaviour of CreateProcess (or winword, I don't know) I wanted to launch winword from my application and be notified when the user close the session I opened, so I used CreateProcess
and WaitForSingleObject
. Here is the code sample from MSDN: SECURITY_ATTRIBUTES sec; sec.bInheritHandle = FALSE; sec.lpSecurityDescriptor = NULL; sec.nLength = sizeof(SECURITY_ATTRIBUTES); STARTUPINFO si; ::ZeroMemory(&si, sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); PROCESS_INFORMATION pi; //notice the 2 slashes after winword.exe if(::CreateProcess(NULL, "C:\\Program Files\\Microsoft Office\\Office\\winword.exe / / C:\\STPMesagElec.doc", NULL,NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) { // Wait for Word to become Idle. WaitForInputIdle(pi.hProcess, 3000); WaitForSingleObject(pi.hProcess,INFINITE); } else { int err = GetLastError(); ::MessageBeep(0); ::MessageBox(NULL, "CreateProcess() failed.\nCheck Path for WinWord.Exe.", "Error", MB_SETFOREGROUND); return; } ::CloseHandle(pi.hThread); ::CloseHandle(pi.hProcess);
Now, the result: - If I use CreateProcess
as above, but without the 2 slashes, it works only when there is no other instance of Word already opened; if a session already exists, WaitForSingleObject
doesn't block anymore - If I use CreateProcess
with the two slashes, it works just as I need it. I noticed that with at least one of the slashes, CreateProcess
creates a new instance of winword.exe, else it opens a new document in the already existing process. Also, with other applications (eg Notepad or even Excel), it works fine without the slashes. Do you think that this is abnormal behaviour? Why it needs the slashes? (i discovered this by pure luck, it isn't documented anywhere) Enis Arif ----------- "I am enough of an artist to draw freely upon my imagination. Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world." (Albert Einstein)