本文介绍了我正在尝试通过 CreateProcess() 在 Sublime Text 中打开一个文件,但构建显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if (CreateProcess("C:\\Program Files\\SublimeText2\\sublime_text",
" source.cpp",
NULL,
NULL,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
NULL,
NULL,
&siStartupInfo,
&piProcessInfo) == FALSE)
WaitForSingleObject(piProcessInfo.hProcess, INFINITE);
::CloseHandle(piProcessInfo.hThread);
::CloseHandle(piProcessInfo.hProcess);
我试图通过 CreateProcess
在 Sublime Text 中打开一个文件,但构建显示以下错误:
I am trying to open a file in Sublime Text through CreateProcess
but the build shows the following errors:
推荐答案
LPWSTR
(Long Pointer to Wide STRing) 是 wchar_t*
,而不是 char*
.您有 3 个选项可以解决问题:
LPWSTR
(Long Pointer to Wide STRing) is a wchar_t*
, not a char*
. You have 3 options to fix the problem:
- 不要使用
UNICODE
#defined 编译. - 使用
CreateProcessA
更改调用以使用宽字符串常量,并显式调用函数的
W
版本,如下所示:
- Don't compile with
UNICODE
#defined. - Use
CreateProcessA
Change the call to use wide string constants, and call the
W
version of the function explicitly, as in:
CreateProcessW(L"C:\\Program Files\\SublimeText2\\sublime_text",
//...
在这三个选项中,您应该使用第三个选项.
Of the three, the third option is the one you should use.
这篇关于我正在尝试通过 CreateProcess() 在 Sublime Text 中打开一个文件,但构建显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!