Kod dla Visual C++ 2008 Express
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( ?, sizeof(pi) );
CreateProcess( TEXT("C:\\Program Files\\Windows Media Player\\wmplayer.exe"),
TEXT("C:\\Program Files\\Windows Media Player\\wmplayer.exe"),
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
? );
LPTSTR pszMessage;
DWORD dwLastError = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwLastError,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&pszMessage,
0, NULL );
wprintf(L"%s\n", pszMessage);
LocalFree(pszMessage);
getchar();
return 0;
}
makra TEXT("") służą zamianie znaków unicode na ascii, jeśli wyłączysz unicode to możesz je pominąc. Podobnie konwersja (LPTSTR) oraz litera "L" w funkcji wprintf