-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.

3
  • 3
    WinMain: The Application Entry Point Commented Oct 10, 2017 at 3:35
  • thank you, i get the answer. Commented Oct 10, 2017 at 4:45
  • 1
    Pass them in exactly the same way. Perhaps your question is how to read them. Commented Oct 10, 2017 at 7:19

3 Answers 3

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().

Sign up to request clarification or add additional context in comments.

1 Comment

thank you, i got it and came up following answers. i have tested it, working as arrow...
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.

5 Comments

There is no ASCII version. There is an ANSI version, tough.
You are right! I corrected my answer.
You still have "argv is the ascii version".
Changed it again!
"__arcg" is a typo. It should be __argc, of course.
-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);

3 Comments

The casts will surely silence the compiler. But once you run the program, you'll see that it fails. Use GetCommandLineW() and wcout, and drop the casts. You should probably also remove all the unrelated code.
Nope, this code is no good.
Great, thank you very much.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.