1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include <tchar.h>
#include <windows.h>
#include <shlwapi.h>
BOOL PathRemoveFileSpecNew(LPTSTR path)
{
LPTSTR newPath = PathFindFileName(path);
if( (newPath) && (newPath != path) ) {
newPath[0] = TEXT('\0');
return 1;
}
return 0;
}
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
TCHAR exePath [MAX_PATH + 1];
GetModuleFileName (GetModuleHandle (NULL), exePath, MAX_PATH);
PathRemoveFileSpecNew ( exePath );
TCHAR exeFullPath [MAX_PATH + 100]; // be carefully here
strcpy (exeFullPath, exePath);
strcat (exeFullPath, TEXT ("Release\\MyProgram.exe"));
strcat (exePath, TEXT ("Release"));
DWORD dwCreationFlags = 0;
#if defined (UNICODE)
dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
#endif // defined
STARTUPINFO si = {0};
si.cb = sizeof (STARTUPINFO);
PROCESS_INFORMATION pi;
if (!CreateProcess (exeFullPath, NULL, NULL, NULL, FALSE, dwCreationFlags, NULL, exePath, &si, &pi)) {
MessageBox (NULL, TEXT ("CreateProcess Failed!"), TEXT ("Error"), MB_OK);
}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return 0;
}
|