-2

char* incompatible with parameter of 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);
}

Any other ways to solve this problem?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Sean Nistar
  • 39
  • 11
  • 1
    And? Yes, they are not compatible: https://msdn.microsoft.com/en-us/library/cc230355.aspx – Matthieu Brucher Nov 01 '18 at 14:37
  • Any reason you are using char string instead of standard strings? – Jake Freeman Nov 01 '18 at 14:39
  • @JakeFreeman please define "standard strings" – Jabberwocky Nov 01 '18 at 14:42
  • @Jabberwocky `std::string` – Jake Freeman Nov 01 '18 at 14:54
  • 1
    @jak: So `std::wstring` is not a *"standard string"* type? And yes, there *are* reasons to not use C++ string types. It's far less troublesome to keep things C at an interface boundary. – IInspectable Nov 01 '18 at 15:10
  • [Working with Strings](https://learn.microsoft.com/en-us/windows/desktop/learnwin32/working-with-strings) answers all your questions, including those you didn't ask. – IInspectable Nov 01 '18 at 15:11
  • Also -- *do not `C`-cast to a different string type to get rid of the compiler error*. You're lucky enough to have stopped at the error and asked the question here, than do what a lot of unaware programmers do, which is to apply an ill-advised cast to the type and then wonder why their program produces gibberish characters. – PaulMcKenzie Nov 01 '18 at 15:16
  • 1
    @bar: That's not correct. [CreateProcessW](https://learn.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-createprocessw) requires a **mutable** string as its second argument. A string literal won't do. – IInspectable Nov 01 '18 at 15:20
  • This question has been closed as a duplicate with 3 references. And gets an upvote. The tooltip on the upvote arrow reads: *"This question shows research effort"*. I'm at a total loss. Would the upvoter please be so kind as to provide rationale for their decision? – IInspectable Nov 01 '18 at 17:28

1 Answers1

1

Yes, that's true.

If you insist on having a char* parameter, call CreateProcessA instead of CreateProcess. Otherwise, make path an LPWSTR too and bring your program into this millenium.

nvoigt
  • 75,013
  • 26
  • 93
  • 142