Reputation: 6079
Working in Windows C++ and using GetCommandLine
to get the arguments in a function. Is there a similar function which would return the number of arguments in the command line?
I am unable to get it from main because I am using the
int WINAPI _tWinMain(HINSTANCE /*hInstance*/,
HINSTANCE /*hPrevInstance*/,
LPTSTR /*lpCmdLine*/,
int /*nShowCmd*/)
main function.
Upvotes: 0
Views: 1102
Reputation: 169
The way is to use another API with GetCommandLine
int numArgs = 0;
LPCWSTR *argv[] = CommandLineToArgvW(GetCommandLineW(), &numArgs);
Now in numArgs a count of arguments, in argv a pointer to an array of arguments. CRT startup code uses this function to build argv
argv[0] is a name of module, argv[n], with n > 0 is a arguments of line, stripped by space
Upvotes: 3