CreateProcess示例 - 注意si的初始化和buffer

作者:半瓶墨水 链接:http://www.2maomao.com/blog/createprocess-sample-usage/
void Helper::StartApp(wstring cmd)
{
    
TCHAR buff[10000] = { 0 };
    
_tcscpy(buff, cmd.c_str());
 
    
PROCESS_INFORMATION pi;
    
STARTUPINFO si = {0};
    
si.cb = sizeof(STARTUPINFO);
 
    
// Create the child process.
    
BOOL bRtn = CreateProcess(
        
NULL,
        
buff,
        
NULL, // process security attributes
        
NULL, // primary thread security attributes
        
TRUE, // handles are inherited
        
0, // creation flags
        
NULL, // use parent's environment
        
NULL, // use parent's current directory
        &
si, // STARTUPINFO pointer
        &
pi); // receives PROCESS_INFORMATION
 
    
if (!bRtn)
    
{
        
MessageBox(NULL, buff,
            
L"CreateProcess failed!", MB_ICONERROR | MB_OK);
    
}
}

试了很久,加了下面两段就没问题了:
1.
TCHAR buff[10000] = { 0 };
_tcscpy(buff, cmd.c_str());

2.
STARTUPINFO si = {0};
si.cb = sizeof(STARTUPINFO);

555,本篇现在一条评论也没有,雁过留声,人过留名,各位乡亲父老,有钱的捧个钱场,没钱的捧个人场......

发表评论

  • :(
  • :)
  • :D
  • :X
  • :^
  • :d
  • :e
  • :h
  • :k
  • :l
  • :p
  • :q
  • :s
  • :v
  • :w
  • :x

注意:评论中需包含至少一个中文字,否则视为无效