#include #include "debug.h" #include "stringutils.h" #include "args.h" // w32 compile: // cl -D_NO_WINDOWS -D_NO_RAPI -EHsc tstcreateproc.cpp -I ../common ..\common\debug.cpp ..\common\stringutils.cpp int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { DebugSetLogfile("tstcreateproc.log"); WStringList args; if (!SplitString(ToWString(lpCmdLine), args, false)) { error("Error in commandline"); return false; } std::wstring imagename; std::wstring cmdline; std::wstring curdir; DWORD flags=0; DWORD params=0; BOOL bInherit=FALSE; WStringList env; #define P_IMGNAME 1 #define P_CMDLINE 2 #define P_ENV 4 #define P_CURDIR 8 #define P_STARTINFO 16 for (WStringList::iterator i= args.begin() ; i!=args.end() ; ++i) { std::wstring& arg= *i; if (arg[0]=='-') switch(arg[1]) { case 'i': HANDLESTLSTROPTION(imagename); params|=P_IMGNAME; break; case 'c': HANDLESTLSTROPTION(cmdline); params|=P_CMDLINE; break; case 'd': HANDLESTLSTROPTION(curdir); params|=P_CURDIR; break; case 'e': { std::wstring keyval; HANDLESTLSTROPTION(keyval); params|=P_ENV; env.push_back(keyval); } break; case 'f': HANDLESTLULOPTION(flags, DWORD); break; case 'h': bInherit= true; break; } } std::wstring nul; nul.resize(1); #ifndef _WIN32_WCE params|=P_STARTINFO; flags |= (params&P_ENV)?CREATE_UNICODE_ENVIRONMENT:0; #endif STARTUPINFOW si; memset(&si, 0, sizeof(si)); si.cb= sizeof(si); PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); std::wstring envstr= JoinStringList(env, nul); if (!CreateProcessW( (params&P_IMGNAME)?imagename.c_str():NULL, (params&P_CMDLINE)?&cmdline[0]:NULL, NULL, // saProcess NULL, // saThread bInherit, // fInheritHandles flags, (params&P_ENV)?&envstr[0]:NULL, #ifndef _WIN32_WCE (params&P_CURDIR)?curdir.c_str(): #endif NULL, (params&P_STARTINFO)?&si:NULL, &pi)) { error("CreateProcess"); return 1; } debug("process: id=%08lx h=%08lx\n", pi.dwProcessId, pi.hProcess); debug("thread : id=%08lx h=%08lx\n", pi.dwThreadId, pi.hThread); return 0; }