# Solved: Parameter Switches



## omuyelijah (Jan 10, 2006)

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.


----------



## JohnWill (Oct 19, 2002)

It's possible to do almost anything with software.  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.


----------



## dez_666 (May 30, 2007)

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.


----------



## omuyelijah (Jan 10, 2006)

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.


----------



## JohnWill (Oct 19, 2002)

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.


----------



## omuyelijah (Jan 10, 2006)

Yes. I want 2 be able to access the command line parameters from my c++ program.


----------



## dez_666 (May 30, 2007)

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.


----------



## JohnWill (Oct 19, 2002)

Here's a page that tells you all about it, including the GetCommandLine() function, which gets you the whole command line.


----------



## dez_666 (May 30, 2007)

Wheres the page JohnWill ()


----------



## JohnWill (Oct 19, 2002)

Oops! http://www.daniweb.com/forums/thread33163.html


----------



## Shadow2531 (Apr 30, 2001)

You can play with this also.


```
#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 √ 2" for example to see what you get.


----------



## omuyelijah (Jan 10, 2006)

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.


----------



## Shadow2531 (Apr 30, 2001)

So, you only want to allow one instance of a program to run?

If so, http://www.codeproject.com/cpp/limitnumins.asp
(Notice the registry method)


----------



## omuyelijah (Jan 10, 2006)

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.


----------



## Shadow2531 (Apr 30, 2001)

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


----------



## omuyelijah (Jan 10, 2006)

A helper application handles program registration as follows:

In the HKEY_CLASSES_ROOT/FOLDER/SHELL key, a subkey ELIOM is created, with a command key (i.e. a key with the name command) bearing the information below:

Folder
!
Shell
!
ELIOM (Application Key)
!
Command

command * (Default) * * REG_SZ* *application.exe "%1"*


----------



## Shadow2531 (Apr 30, 2001)

O.K. cool. I can reproduce the problem. Now, to solve it.


----------



## Shadow2531 (Apr 30, 2001)

Well, the reason you get multiple windows has nothing to do with the "%" argument you're using.

When you click on the item in the context menu, explorer is doing this:


```
foreach (folders_selected : path_of_folder) {
    ShellExecute(NULL, "open", "application.exe", path_of_folder);
}
```
So, you can see why it happens.

You can also try it under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory , but you'll get the same result.

I think you might have to make your program use DDE and add a ddeexec key to the registry. I have no clue how to do either though. Maybe there is an easier way though.

Your program works fine if you select the folders and drag them onto your exe, right?


----------



## omuyelijah (Jan 10, 2006)

A helper application handles program registration as follows:

In the HKEY_CLASSES_ROOT/FOLDER/SHELL key, a subkey ELIOM is created, with a command key (i.e. a key with the name command) bearing the information below:

Folder
!
Shell
!
ELIOM (Application Key)
!
Command

*command (Default) REG_SZ application.exe "%1"*


----------



## omuyelijah (Jan 10, 2006)

My application does not support drag n drop for now. However, I'll try the DDE thing you talked about. Thanks 4 ur concern so far. I appreciate it.


----------



## omuyelijah (Jan 10, 2006)

Hello, all

I was able to achieve this, with Microsoft Drag n drop technology in COM. 

Thanks all.

Bye.


----------

