我正在尝试使用createprocess函数从我的代码启动一个进程。命令行是正常的,而另一个exe,我可以从visual studio启动它而没有问题。
当我试图用createprocess从另一个进程启动它时,它给了我-运行时错误,这个应用程序请求运行时以一种不寻常的方式终止它。
可能的问题是什么?我怎样才能解决这个问题?
STARTUPINFO si;
PROCESS_INFORMATION pi;
bool bResult;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
//Cast System::String* __gc to char*
char* chAppName = (char*)(void*)Marshal::StringToHGlobalAnsi(AppName);
char* chCmdLine = (char*)(void*)Marshal::StringToHGlobalAnsi(CmdLine);
//Start the child process.
bResult = CreateProcess( chAppName, // No module name (use command line)
chCmdLine, // 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 发布于 2013-06-24 18:56:18
尝试消除StringToHGlobalAnsi调用,并首先对其进行硬编码。如果这停止了问题,那么我们就可以解决StringToHGlobalAnsi调用了。
https://stackoverflow.com/questions/17273487
复制相似问题