-4

folks.

i want pass argv parameters in my GUI program which written c++, my program is not the black screen console, but it is a GUI. for example my program is AAA.exe, and i want to pass a command like "AAA.exe doThing" etc. how can i do it? thank you all so much.

Aqtemir
  • 1
  • 1
  • 5

3 Answers3

3

While WinMain is the application entry point, it does not help you very much with command line arguments.

(You can get the command line from anywhere using GetCommandLine().)

You can parse it using CommandLineToArgvW().

Dúthomhas
  • 8,200
  • 2
  • 17
  • 39
1

If you use VS you can easily use __argc and __argv.

These variables are automatically populated by the CRT. The variables are available in an MBCS/ANSI version and an Unicode version. __argv is the MBCS/ANSI version, whereas __wargv is the unicode version.

To use them we have just to include stdlib.h. there is also a __targv version available when you include TCHAR.h.

IInspectable
  • 46,945
  • 8
  • 85
  • 181
xMRi
  • 14,982
  • 3
  • 26
  • 59
-2

came up with following answers, it was tested and working nicely as arrow. added this code in WinMain block.

LPWSTR *szArgList;
int argCount;

 szArgList = CommandLineToArgvW((LPWSTR)GetCommandLine(), &argCount);
 if (szArgList == NULL){
     MessageBox(NULL, "Unable to parse command line", "Error", MB_OK);
     return 10;
 }
 int wint = 1;
 for(int i = 0; i < argCount; i++){
    cout << "szArgList[i]: " << (LPSTR)szArgList[i] << endl;
    string argsbek= (LPSTR)szArgList[i];
    if (argsbek.find(" passMyword") != string::npos){
       cout <<"words are passed ..."<<endl;
       wint=2;
    }
 }
 LocalFree(szArgList);
Aqtemir
  • 1
  • 1
  • 5