我正在尝试通过 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:
const char *"类型的参数与LPWSTR"类型的参数不兼容.
argument of type "const char *" is incompatible with parameter of type "LPWSTR".
const char *"类型的参数与LPWCSTR"类型的参数不兼容.
argument of type "const char *" is incompatible with parameter of type "LPWCSTR" .
'BOOL CreateProcessW(LPCWSTR,LPWSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCWSTR,LPSTARTUPINFOW,LPPROCESS_INFORMATION)': 无法将参数 1 从 'const char [32]' 转换为 'LPCW>
'BOOL CreateProcessW(LPCWSTR,LPWSTR,LPSECURITY_ATTRIBUTES,LPSECURITY_ATTRIBUTES,BOOL,DWORD,LPVOID,LPCWSTR,LPSTARTUPINFOW,LPPROCESS_INFORMATION)': cannot convert argument 1 from 'const char [32]' to 'LPCWSTR' .
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.