Search code examples
cprogram-entry-pointwmain

main() wrapper to start wmain() program to compile it from commandline


For example i have a program thats "main" function is defined as wmain.

int wmain( int argc, wchar_t *argv[] ) {
    wchar_t* lpModulePath = NULL;
    wchar_t* lpFunctionName = NULL;
    lpModulePath = argv[1];
    lpFunctionName = argv[2];
}

and of course uses wchar_t types. How can i write a function

int main( int argc, char *argv[] )

that converts the parameters passed as char to wchar_t and then calls wmain by itself?

Thank you


Solution

  • On Windows you can use GetCommandLineW() and CommandLineToArgvW():

    int main(int argc, char* argv[])
    {
        wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc);
        int ret = wmain(argc, wargv);
        LocalFree(wargv);
        return ret;
    }
    

    On Linux I'm afraid you'd have to allocate the array and convert strings in loop.