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

CreateProcess

Status
Not open for further replies.

Doctor

Programmer
Aug 12, 1999
2
US
Need help in using create process in win32 application in VC++, preferrably the simpler way. Also is it possible to use the same method to launch an application in VB 6.0 and have it return a handle to the new process so that it can be shut down from within the same application even though both processes are running separately.
 
BOOL CreateProcess(<br>&nbsp;&nbsp;LPCTSTR lpApplicationName,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// pointer to name of executable module<br>&nbsp;&nbsp;LPTSTR lpCommandLine,&nbsp;&nbsp;// pointer to command line string<br>&nbsp;&nbsp;LPSECURITY_ATTRIBUTES lpProcessAttributes,&nbsp;&nbsp;// process security attributes<br>&nbsp;&nbsp;LPSECURITY_ATTRIBUTES lpThreadAttributes,&nbsp;&nbsp;&nbsp;// thread security attributes<br>&nbsp;&nbsp;BOOL bInheritHandles,&nbsp;&nbsp;// handle inheritance flag<br>&nbsp;&nbsp;DWORD dwCreationFlags, // creation flags<br>&nbsp;&nbsp;LPVOID lpEnvironment,&nbsp;&nbsp;// pointer to new environment block<br>&nbsp;&nbsp;LPCTSTR lpCurrentDirectory,&nbsp;&nbsp;&nbsp;// pointer to current directory name<br>&nbsp;&nbsp;LPSTARTUPINFO lpStartupInfo,&nbsp;&nbsp;// pointer to STARTUPINFO<br>&nbsp;&nbsp;LPPROCESS_INFORMATION lpProcessInformation&nbsp;&nbsp;// pointer to PROCESS_INFORMATION<br>);<br><br>If you have MSDN installed it tells all the parameteres, although I think there is something more simple than CreateProccess to execute a program (and hold its handle). also search msdn.microsoft.com just in case I cant find anything. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
this might help.<br><br><FONT FACE=monospace><br>INFO: Understanding CreateProcess and Command-line Arguments<br>Last reviewed: October 30, 1997<br>Article ID: Q175986&nbsp;&nbsp;<br>The information in this article applies to: <br>Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows NT, versions 3.51, 4.0 - Microsoft Windows 95 <br><br><br>SUMMARY<br>This article explains the relationship between the ApplicationName and CommandLine parameters of the CreateProcess() API, specifically to clarify any issues that arise when you use both parameters. <br><br><br><br>MORE INFORMATION<br>The first two parameters of the CreateProcess API are ApplicationName and CommandLine. The behavior of these parameters differs depending upon whether you are creating a 32-bit process or a 16-bit executable. <br><br><br><br>Behavior of CreateProcess() When Creating a 32-bit Process<br>Case 1: <br><br>If the ApplicationName parameter is passed and the CommandLine parameter is NULL, then the ApplicationName parameter is also used as the CommandLine. This does not mean that you can pass additional command-line parameters in ApplicationName string. For example, the following call will fail with a &quot;File Not Found&quot; error: <br><br><br>&nbsp;&nbsp;CreateProcess( &quot;c:\\MyApp.exe Param1 Param2&quot;, NULL, ... )<br><br><br>Case 2: <br>On the other hand, if the CommandLine parameter is non-NULL and the ApplicationName parameter is NULL, then the API attempts to extract the application name from the CommandLine parameter. <br><br>Case 3: <br><br>The flexibility of the CreateProcess() function (and a possible point of confusion) arises when you pass a valid string pointer to both the ApplicationName and CommandLine parameters. This allows you to specify the application to be executed as well as the complete command line that is passed to the application. One might assume that the command line passed to the created application is a composite of the ApplicationName and CommandLine parameters, but this is not the case. As a result, a process created by CreateProcess can receive a value other than its .exe name as its &quot;argv[0]&quot; parameter. The following is an example of a call to CreateProcess that produces this &quot;abnormal&quot; behavior: <br><br><br>&nbsp;&nbsp;CreateProcess( &quot;c:\\MyApp.exe&quot;, &quot;Param1 Param2 Param3&quot;, ...)<br><br><br>MyApp's arguments will be as follow: <br><br>&nbsp;&nbsp;argv[0] == &quot;Param1&quot;<br>&nbsp;&nbsp;argv[1] == &quot;Param2&quot;<br>&nbsp;&nbsp;argv[2] == &quot;Param3&quot;<br><br><br>NOTE: ANSI specifications require that argv[0] should be equal to the application name, but CreateProcess gives the calling application the flexibility to override this rule for 32-bit processes. <br><br><br>Behavior of CreateProcess When Executing a 16-bit .exe<br>CreateProcess() does enforce the ANSI specification for parameters passed to 16-bit applications. This raises a potentially confusing inconsistency between the way CreateProcess works from one application to the next and requires you to know whether the application that you are spawning is a 16- bit or 32-bit executable file. To further complicate the issue, CreateProcess is implemented slightly differently in Windows 95 and Windows NT. <br><br>Windows NT Behavior: <br><br>If the first &quot;parameter&quot; in the CommandLine is not exactly the same as the ApplicationName string, then it replaces it before executing the application. For example if the ApplicationName and CommandLine parameters are as follows: <br><br><br>&nbsp;&nbsp;&nbsp;CreateProcess( &quot;c:\\MyApp16.exe&quot;, &quot;Param1 Param2 Param3&quot;, ...)<br><br><br>Then, the command line arguments that the application sees are as follows: <br><br>&nbsp;&nbsp;argv[0] == &quot;c:\MyApp16.exe&quot;<br>&nbsp;&nbsp;argv[1] == &quot;Param2&quot;<br>&nbsp;&nbsp;argv[2] == &quot;Param3&quot;<br><br><br>Windows 95 Behavior: <br>If the first &quot;parameter&quot; in the CommandLine is not exactly the same as the ApplicationName string, then CreateProcess fails with a file not found error. As a result, there is no reason to pass anything but NULL as the ApplicationName argument to CreateProcess in Windows 95 if you are executing a 16-bit application<br>&nbsp;<br></font> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top