我正在尝试通过 CreateProcess() 在 Sublime Text 中打开一个文件,但构建显示错误 [英] I am trying to open a file in Sublime Text through CreateProcess() but the build shows errors

查看:30
本文介绍了我正在尝试通过 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:

    1. 不要使用 UNICODE #defined 编译.
    2. 使用CreateProcessA
    3. 更改调用以使用宽字符串常量,并显式调用函数的 W 版本,如下所示:

    1. Don't compile with UNICODE #defined.
    2. Use CreateProcessA
    3. 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 中打开一个文件,但构建显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆