Menu

CreateProcess not working

2005-03-29
2012-09-26
  • Nobody/Anonymous

    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++

     
    • Anonymous

      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

      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

       
    • Nobody/Anonymous

      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);

                      // Wait until child process exits. 
                      while( WaitForSingleObject( pi.hProcess, 1000 ) != WAIT_OBJECT_0 ) 
                      { 
                          // do nothing 
                      }
      
                      // Close process and thread handles. 
                      CloseHandle( pi.hProcess ); 
                      CloseHandle( pi.hThread );
      
                      MessageBox(NULL,"You have killed the spawn !!!","Closed",MB_ICONINFORMATION);
      

      Is there a different way with ShellExecute? Thanks!

      My Shell Execute: (it works fine)

      ShellExecute(hwnd, "open", excel, NULL, dir1, SW_SHOW);

       
    • Anonymous

      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().

      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

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.