« | October 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | |
| 公告 |
暂无公告... |
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." ); }通过。 |
|
|