Ohav
Ohav

Reputation: 671

How to get argv as LPWSTR* and not char** from command line arguments?

I am writing a small C++ program which gets as input from the program command line, a string to later be passed to another function.

The problem is that this function expects to get a LPWSTR (wchar_t*) type variable, and the regular char** argv is an array of elements from the type of char*.

Is there any way to get the argv variable as a LPWSTR* type?

Thanks

Upvotes: 1

Views: 824

Answers (1)

Ohav
Ohav

Reputation: 671

A simple solution can be acheived by combining both GetCommandLineW() and CommandLineToArgvW() in the following way:

int main() {
    int argc = 0;
    LPWSTR* pArgvW = CommandLineToArgvW(GetCommandLineW(), &argc);
    // use pArgvW as needed...
    LocalFree(pArgvW);
    ...
    return 0;
}

Reading GetCommandLineW and CommandLineToArgvW documentation might also help.

Upvotes: 3

Related Questions