I came across an application code and see that for the "Windows" specific code they have converted the command line arguments to do some additional WCHAR related processing (between #ifdef _WIN32).
What would be the reason for adding WCHAR processing related code for Windows in below snippet? I am trying to understand the rationale behind invoking the WCHAR related functions. In the end, the coder is trying to call myFunc
which could have directly been called using normal argC and argV. Why would someone feel to need to add additional processing of wchar?
int main(int argc, char* argv[])
{
#ifdef _WIN32
int argc_w;
LPWSTR* argv_w = CommandLineToArgvW(GetCommandLineW(), &argc_w);
std::vector<char*> argv_vector;
int result;
if (ConvertToUtf8(argc_w, argv_w, argv_vector)) {
result = myFunc(argc_w, argv_vector.data());
} else {
result = myFunc(argc, argv);
}
// code to free vector
return result;
#else
int (*ptrMyFunc)(int, char**, const char*);
void *dllHandle = dlopen(myDLL.c_str(), RTLD_LAZY);
*(void **) (&ptrMyFunc) = dlsym(dllHandle, "myFunc");
return (*ptrMyFunc)(argc, argv);
#endif
}