1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Parameter Switches

Discussion in 'Software Development' started by omuyelijah, Jul 18, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. omuyelijah

    omuyelijah Thread Starter

    Joined:
    Jan 10, 2006
    Messages:
    120
    Hello,

    It is possible to register an application in the Windows Registry passing parameters to it, where we specify %1, %2, e.t.c. for first and second parameters. How can I access all parameters w/o specifying %1, %2? Is there a switch to use such that I get all parameters in the args[] array?

    Thanks in advance.
     
  2. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
    It's possible to do almost anything with software. :D Perhaps you could be specific as to your development environment, the language you're developing in, and exactly the behavior you desire. You can certainly access all the parameters in the command line arguments.
     
  3. dez_666

    dez_666

    Joined:
    May 29, 2007
    Messages:
    842
    AFAIK, this is what an installer is for.

    I know a great installer program for making installers/uninstallers.

    Chex it here http://www.advancedinstaller.com
    You can do LOADS of stuff with the freeware version too. :)

    you could always use the windows command 'reg' in your program. :D:D:D
     
  4. omuyelijah

    omuyelijah Thread Starter

    Joined:
    Jan 10, 2006
    Messages:
    120
    I'm programming in Visual 2005 C++ .NET, Windows XP Home Edition sp2. Thanks Dez_666; I have Advanced Installer but I want this feature programmatically from C++. What about the windows 'reg' command?

    Thanks in advance.
     
  5. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
    Are you writing a C++ application that you want to access the command line parameters? I still don't see a clear statement of what you're trying to accomplish here.
     
  6. omuyelijah

    omuyelijah Thread Starter

    Joined:
    Jan 10, 2006
    Messages:
    120
    Yes. I want 2 be able to access the command line parameters from my c++ program.
     
  7. dez_666

    dez_666

    Joined:
    May 29, 2007
    Messages:
    842
    You could just google "C++ Command line parameters". Ive looked it up before but all I know about C++ is int, cout and cin :)
    And from what ive read it is cake, I just dont know how to do it.
     
  8. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
    Here's a page that tells you all about it, including the GetCommandLine() function, which gets you the whole command line.
     
  9. dez_666

    dez_666

    Joined:
    May 29, 2007
    Messages:
    842
    Wheres the page JohnWill (o_O)
     
  10. JohnWill

    JohnWill Retired Moderator

    Joined:
    Oct 19, 2002
    Messages:
    106,418
  11. Shadow2531

    Shadow2531

    Joined:
    Apr 30, 2001
    Messages:
    2,636
    You can play with this also.

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <windows.h>
    #include <cstdio>
    #include <cwchar>
    #include <clocale>
    using namespace std;
    
    int main(int argc, char** argv) {
        for (int i = 0; i < argc; ++i) {
            cout << argv[i] << "\n";
        }
    
        char* ansi_args_as_string = GetCommandLineA();
        cout << ansi_args_as_string << "\n\n";
        
        setlocale(LC_CTYPE, ".OCP");
        
        int argc2;
        wchar_t** argv2 = CommandLineToArgvW(GetCommandLineW(), &argc2);
        if (!argv2) {
            return EXIT_FAILURE;
        }
        for (int i = 0; i < argc2; ++i) {
            wprintf(L"%s\n", argv2[i]);
        }
        LocalFree(argv2);
        
        wchar_t* unicode_args_as_string = GetCommandLineW();
        wprintf(L"%s\n", unicode_args_as_string);
    }
    
    Test it with "program.exe 1 &#8730; 2" for example to see what you get.
     
  12. omuyelijah

    omuyelijah Thread Starter

    Joined:
    Jan 10, 2006
    Messages:
    120
    I've tried all ur suggestions and they are O.k. Infact, I had used the args[] array parameter from the C++ application but there is an unexpected output I don't want.

    Referring to your sampe code, Shadow2531, the unexpected output (just as I had in mine) is at the first FOR loop in the main function; more than 1 instance of the program is created (i.e. more than 1 console window, displaying the arguements in the array).

    My fear is that it might produce unexpected resuts in my application as I use the arguements for further processing. I only want an instance of the program to run instead of the multiples I get, hence I asked if there was any registry switch other than %1 ,%2, ... that can be used 2 achieve this.

    Thanks in advance.
     
  13. Shadow2531

    Shadow2531

    Joined:
    Apr 30, 2001
    Messages:
    2,636
  14. omuyelijah

    omuyelijah Thread Starter

    Joined:
    Jan 10, 2006
    Messages:
    120
    Hello,

    Thanks for the resources but they still don't get me the needed operability. I think I should come out clear with describing the problem here.
    The application at hand is registered in the Windows Registry to be invoked from clicking a menu item (from a context menu, displayed from right-clicking on any folder). The application gets the commandline arguements and only needs the folder information to work. It is supposed to get folder names for more than 1 selected folders but it opens more than one console windows (or even form object), showing each folder name in each opened program instance. This behaviour is unwanted. Can't I get information for all selected folders in a single program instance?

    Could it be from the registration in the windows Registry? Here are the registration methods I tried:

    1. application.exe "%1"
    2. application.exe "%*"
    3. application.exe "%1" "%*"

    This is the situation.
     
  15. Shadow2531

    Shadow2531

    Joined:
    Apr 30, 2001
    Messages:
    2,636
    ^^ Show us what key you're adding to the registry and I'll test to see how the reg key needs to be set up and whether it's your app or just a reg command problem.
     
  16. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/597255

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice