3 #error Need C++ to compile
10 #pragma warning(push, 1)
28 # define GetArgv( pArgc ) CommandLineToArgvW( GetCommandLine(), pArgc )
29 # define PROCESS_CREATIONFLAGS CREATE_UNICODE_ENVIRONMENT
31 # define GetArgv( pArgc ) (*pArgc = __argc, __argv)
32 # define PROCESS_CREATIONFLAGS 0
36 #define BIN_EXT_STR TEXT(".bin")
37 #define PARAM_LIBPATH_STR TEXT("-libpath=")
38 #define PARAM_LOCAL_STR TEXT("-local")
39 #define PARAM_REMOTE_STR TEXT("-remote")
42 #define DEFAULT_LIBPATH TEXT("remote;")
43 #elif defined( LOCAL )
44 #define DEFAULT_LIBPATH TEXT("local;")
49 // Retreive startup info
51 STARTUPINFO aStartupInfo
;
53 ZeroMemory( &aStartupInfo
, sizeof(aStartupInfo
) );
54 aStartupInfo
.cb
= sizeof( aStartupInfo
);
55 GetStartupInfo( &aStartupInfo
);
57 // Retrieve command line
59 LPTSTR lpCommandLine
= GetCommandLine();
61 LPTSTR
*ppArguments
= NULL
;
64 ppArguments
= GetArgv( &nArguments
);
66 // Calculate application name
69 TCHAR szApplicationName
[MAX_PATH
];
70 TCHAR szDrive
[MAX_PATH
];
71 TCHAR szDir
[MAX_PATH
];
72 TCHAR szFileName
[MAX_PATH
];
73 TCHAR szExt
[MAX_PATH
];
75 GetModuleFileName( NULL
, szApplicationName
, MAX_PATH
);
76 _tsplitpath( szApplicationName
, szDrive
, szDir
, szFileName
, szExt
);
77 _tmakepath( szApplicationName
, szDrive
, szDir
, szFileName
, BIN_EXT_STR
);
79 // Retreive actual environment
82 TCHAR szPathValue
[1024] = TEXT("");
84 #ifdef DEFAULT_LIBPATH
85 _tmakepath( szPathValue
, szDrive
, szDir
, DEFAULT_LIBPATH
, TEXT("") );
88 for ( int argn
= 1; argn
< nArguments
; argn
++ )
90 if ( 0 == _tcscmp( ppArguments
[argn
], PARAM_REMOTE_STR
) )
92 _tmakepath( szPathValue
, szDrive
, szDir
, TEXT("remote;"), TEXT("") );
95 else if ( 0 == _tcscmp( ppArguments
[argn
], PARAM_LOCAL_STR
) )
97 _tmakepath( szPathValue
, szDrive
, szDir
, TEXT("local;"), TEXT("") );
100 else if ( 0 == _tcsncmp( ppArguments
[argn
], PARAM_LIBPATH_STR
, _tcslen(PARAM_LIBPATH_STR
) ) )
102 LPTSTR pFileSpec
= NULL
;
104 GetFullPathName( ppArguments
[argn
] + _tcslen(PARAM_LIBPATH_STR
), sizeof(szPathValue
) / sizeof(TCHAR
), szPathValue
, &pFileSpec
);
105 _tcscat( szPathValue
, TEXT(";") );
110 GetEnvironmentVariable( TEXT("PATH"), szBuffer
, sizeof(szBuffer
) );
111 _tcscat( szPathValue
, szBuffer
);
112 SetEnvironmentVariable( TEXT("PATH"), szPathValue
);
114 LPVOID lpEnvironment
= GetEnvironmentStrings();
117 // Retrieve current directory
119 TCHAR szCurrentDirectory
[MAX_PATH
];
120 GetCurrentDirectory( MAX_PATH
, szCurrentDirectory
);
124 DWORD dwCreationFlags
= PROCESS_CREATIONFLAGS
;
126 PROCESS_INFORMATION aProcessInfo
;
128 BOOL fSuccess
= CreateProcess(
144 WaitForSingleObject( aProcessInfo
.hProcess
, INFINITE
);
145 fSuccess
= GetExitCodeProcess( aProcessInfo
.hProcess
, &dwExitCode
);
150 DWORD dwError
= GetLastError();
155 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
156 FORMAT_MESSAGE_FROM_SYSTEM
,
159 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
165 // Display the string.
166 MessageBox( NULL
, (LPCTSTR
)lpMsgBuf
, NULL
, MB_OK
| MB_ICONERROR
);
169 LocalFree( lpMsgBuf
);
171 return GetLastError();