Problem mit CreateProcess
-
Hallo! Hab dieses Code:
PPROCESS_INFORMATION pi; if (!CreateProcess(app_s, 0, 0, 0, 0, 0, 0, 0, 0, &pi)) throw build_error(); WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hProcess); CloseHandle(pi.hThread);Das geht aber net, denn :
Error 4 error C2664: 'CreateProcessW' : cannot convert parameter 10 from 'PPROCESS_INFORMATION *' to 'LPPROCESS_INFORMATION'
Hab schon in der Doku geschaut. Dort wirds so gemacht...
Edit: Hab mich vertippt - es muss PROCESS_INFORMATION heißen und nicht PPROCESS_INFORMATION...
-
In welcher Doku hast Du denn geaschaut? Das wird es mit sicherheit *nicht* so gemacht!
-
Doch, doch. Die MSDN lügt nie
Ich habe aber noch ein 'P' vor PROCESS_INFORMATION geschrieben...Das Problem ist jetzt, dass es nie funzt. Vielleicht muss ich mal das Programm im 2. Parameter übergeben?
-
Zeig mir mal bitte den Link!
Mein Link:
http://msdn.microsoft.com/en-us/library/ms682425Und das Beispiel ist:
LPTSTR szCmdline[] = _tcsdup( TEXT("\"C:\\Program Files\\MyApp\" -L -S")); CreateProcess(NULL, szCmdline, ...)
-
ms-help://MS.MSDNQTR.v90.en/dllproc/base/creating_processes.htm
Creating Processes
The CreateProcess function creates a new process, which runs independently of the creating process. However, for simplicity, the relationship is referred to as a parent-child relationship.The following code demonstrates how to create a process.
#include <windows.h>
#include <stdio.h>
#include <tchar.h>void _tmain( int argc, TCHAR *argv[] )
{
STARTUPINFO si;
PROCESS_INFORMATION pi;ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );if( argc != 2 )
{
printf("Usage: %s [cmdline]\n", argv[0]);
return;
}// Start the child process.
if( !CreateProcess( NULL, // No module name (use command line)
argv[1], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d)\n", GetLastError() );
return;
}// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}If CreateProcess succeeds, it returns a PROCESS_INFORMATION structure containing handles and identifiers for the new process and its primary thread. The thread and process handles are created with full access rights, although access can be restricted if you specify security descriptors. When you no longer need these handles, close them by using the CloseHandle function.
You can also create a process using the CreateProcessAsUser or CreateProcessWithLogonW function. This allows you to specify the security context of the user account in which the process will execute.
Send comments about this topic to Microsoft
Build date: 8/15/2007
Bist du damit zufrieden?
-
In dem von Dir geposteten Sample kommt kein PPROCESS_INFORMATION vor. vor.
Wenn PPROCESS_INFORMATION eine Struktur ist, dann sind in der Windows API meistens sofort PPPROCESS_INFORMATION definiert als Zeiger auf PROCESS_INFORMATION.
Dein Code ist also falsch, weil Du keinen Zeiger rauchst sondern eine ganze Struktur.
-
Gut, und wie kann ich auf ERRORLEVEL zugreifen? Nach der Ausführung des Prozesses wird gesagt, dass ERRORLEVEL einen Wert bekommt. Wie kann ich ihn lesen?
-
GetExitCodeProcess!
http://msdn.microsoft.com/en-us/library/ms683189(VS.85).aspx
-
Mal schauen...
ZeroMemory(&pi, sizeof(pi)); <- das brauche ich nicht, oder? Das Programm läuft gut auch ohne dies...
-
DU brauchst alles was in dem Beispiel ist... (ist das zu fassen !?)
-
Ja, schon. Danke!