我正在尝试创建一个使用CreateProcess调用另一个进程的程序.遇到一些问题后,我将程序更改为只打开一个已知程序:
Run Code Online (Sandbox Code Playgroud)if( !CreateProcess( (LPWSTR)"C:\\Program Files\\Opera\\Opera.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 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 )
我在msdn中找到了这个例子,但是每次运行我的程序时,windows(Vista)都显示错误消息:程序停止运行...
有谁知道这是什么问题?
此致,Leandro Lima
这条线错了:
(LPWSTR)"C:\\Program Files\\Opera\\Opera.exe"
Run Code Online (Sandbox Code Playgroud)
LPWSTR是一个typedef wchar_t*.所以你要将一个普通的字符串(字符数组,它会衰减到a const char*)转换为a wchar_t*.最终结果可能甚至没有终止!
使用CreateProcessA和删除演员表,或使用宽字符串:
L"C:\\Program Files\\Opera\\Opera.exe",
Run Code Online (Sandbox Code Playgroud)