Can someone explain why CreateProcess will only let you open a .exe file. It gives no errors at all, execpt it locks up when it comes to the line with CreateProcess. I'm trying to open .doc file. Wouldn't it open it in the default program? I can't use shell execute either, it has to be CreateProcess. Thanks!
Dev C 4.9.9.2 Win32 GUI C/C++
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2005-03-29
CreateProcess() only works for executables. (.exe or .com):http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2005-03-29
Sorry, I misunderstood. I thought you were saying that ShellExecute() did not work. I see that is not what you said!
The fact remains that CreateProcess needs ot be told what exe to use. I have found several references to finding the associated EXE in Delphi (but strangely not C), maybe you could adapt that to find the EXE and plug it into CreateProcess().
Can someone explain why CreateProcess will only let you open a .exe file. It gives no errors at all, execpt it locks up when it comes to the line with CreateProcess. I'm trying to open .doc file. Wouldn't it open it in the default program? I can't use shell execute either, it has to be CreateProcess. Thanks!
Dev C 4.9.9.2 Win32 GUI C/C++
CreateProcess() only works for executables. (.exe or .com):http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp
ShellExecute() is precisely what you need to use. If you cannot get it to work, post the code you are using. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp
I'd suggest something like:
ShellExecute( NULL, "open", document, NULL, NULL, SW_SHOWNORMAL ) ;
where document is a null terminated string containing the path for the document to be opened.
Clifford
Well I need to know when the document (MSWORD) is closed by the user. The only way I know of to do that is:
PROCESS_INFORMATION pi;
STARTUPINFO si;
// prpare execution structures
memset( &si, 0, sizeof(si) );
si.cb = sizeof(si);
memset( &pi, 0, sizeof(pi) );
CreateProcess(NULL, "C:\WINDOWS\NOTEPAD.EXE", NULL, NULL, 0, 0, NULL, NULL, &si, &pi);
Is there a different way with ShellExecute? Thanks!
My Shell Execute: (it works fine)
ShellExecute(hwnd, "open", excel, NULL, dir1, SW_SHOW);
Sorry, I misunderstood. I thought you were saying that ShellExecute() did not work. I see that is not what you said!
The fact remains that CreateProcess needs ot be told what exe to use. I have found several references to finding the associated EXE in Delphi (but strangely not C), maybe you could adapt that to find the EXE and plug it into CreateProcess().
http://delphi.about.com/cs/adptips2003/a/bltip0103_3.htm
http://www.howtodothings.com/viewarticle.aspx?article=593
As an aside, you could use:
WaitForSingleObject( pi.hProcess, INFINITE ) ;
rather than the while loop.
Clifford