CreateProcess函数问题

CreateProcess function issue

本文关键字:问题 函数 CreateProcess      更新时间:2023-10-16

我正试图用createprocess函数从代码中启动一个进程。命令行是可以的,另一个exe,我可以从visualstudio启动它,没有问题。

当我试图用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 

尝试先消除StringToHGlobalAnsi调用并对其进行硬编码。如果这停止了问题,那么我们就可以对StringToHGlobalAnsi调用进行排序。