本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告
暂无公告...

我的分类(专题)

日志更新

最新评论

留言板

链接


Blog信息
blog名称:
日志总数:29
评论数量:48
留言数量:0
访问次数:189449
建立时间:2006年5月24日




[Windows开发]CreateProcess调用失败,内存访问错误
心得体会,  软件技术

wangchuanfa 发表于 2006/7/3 17:48:14

编写一个Dll,其中用CreateProcess创建新进程,代码如下:     STARTUPINFO si;    ZeroMemory( &si, sizeof(si) );    si.cb = sizeof(si);    PROCESS_INFORMATION pi;    ZeroMemory( &pi, sizeof(pi) );    if( !CreateProcess( NULL, // No module name (use command line).        _T("c:\\windows\\Notepad.exe"), // Command line.         NULL,             // Process handle not inheritable.         NULL,             // Thread handle not inheritable.         FALSE,            // Set handle inheritance to FALSE.         NULL,                // 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.    )     {//       TRACE( "CreateProcess failed." );    }结果调用时发生内存访问错误! 经过一段时间分析,发现可能是UNICODE版本问题,回头在查MSDN,赫然存在这么一句话: lpCommandLine: The Unicode version of this function, CreateProcessW, will fail if this parameter is a const string.晕到醒来后,改为如下调用方式:     STARTUPINFO si;    ZeroMemory( &si, sizeof(si) );    si.cb = sizeof(si);    PROCESS_INFORMATION pi;    ZeroMemory( &pi, sizeof(pi) );    if( !CreateProcess(  _T("c:\\windows\\Notepad.exe"),  // No module name (use command line).       NULL,// Command line.         NULL,             // Process handle not inheritable.         NULL,             // Thread handle not inheritable.         FALSE,            // Set handle inheritance to FALSE.         NULL,                // 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.    )     {//       TRACE( "CreateProcess failed." );    }通过。


阅读全文(2844) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.626 second(s), page refreshed 144815943 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号