0

我正在尝试使用 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 
4

1 回答 1

0

尝试先消除StringToHGlobalAnsi呼叫并对其进行硬编码。如果这停止了问题,我们就可以整理StringToHGlobalAnsi电话。

于 2013-06-24T10:56:18.140 回答