【问题标题】:char* incompatible with parameter of LPWSTR for C++ [duplicate]char *与C ++的LPWSTR参数不兼容[重复]
【发布时间】:2019-04-05 19:19:27
【问题描述】:

char*与LPWSTR参数不兼容

void ConnectToEngine(char* path)
{

    pipin_w = pipin_r = pipout_w = pipout_r = NULL;
    sats.nLength = sizeof(sats);
    sats.bInheritHandle = TRUE;
    sats.lpSecurityDescriptor = NULL;

    CreatePipe(&pipout_r, &pipout_w, &sats, 0);
    CreatePipe(&pipin_r, &pipin_w, &sats, 0);

    sti.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    sti.wShowWindow = SW_HIDE;
    sti.hStdInput = pipin_r;
    sti.hStdOutput = pipout_w;
    sti.hStdError = pipout_w;

    CreateProcess(NULL, path, NULL, NULL, TRUE, 0, NULL, NULL, &sti, &pi);
}

还有其他方法可以解决这个问题吗?

【问题讨论】:

  • 然后呢?是的,它们不兼容:msdn.microsoft.com/en-us/library/cc230355.aspx
  • 您使用 char 字符串而不是标准字符串的任何原因?
  • @JakeFreeman 请定义“标准字符串”
  • @jak:所以std::wstring 不是“标准字符串” 类型?是的,有 are 理由不使用 C++ 字符串类型。将事物 C 保持在接口边界上要容易得多。
  • @bar:这不正确。 CreateProcessW 需要一个 mutable 字符串作为其第二个参数。字符串文字不行。

标签: c++ winapi char


【解决方案1】:

是的,没错。

如果您坚持使用char* 参数,请调用CreateProcessA 而不是CreateProcess。否则,将path 也设为LPWSTR 并将您的程序带入这个千年。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 2020-01-20
    • 2021-01-07
    • 2014-07-03
    • 1970-01-01
    • 2019-12-16
    • 2016-05-19
    相关资源
    最近更新 更多