Public Group

# Passing a file from extension to command args when running a program?

This topic is 2556 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

A pretty raggedy question, I couldn't really find exact answers to...

So, I want to make a file extension for a file type I'm using with my program, and I want that after the extension is set, and the file with that extension is double clicked, I want it to feed the file's path as a startup command argument in the program, so, how do I do it?

Currently, I have this:
 exeFolder = Environment::CurrentDirectory; String^ keyName = "HKEY_CURRENT_USER\\Software\\Classes"; String^ subKey = \\SilverBridge.Phantasya; //Registring the file extension if not already registered String^ reg = Convert::ToString(Registry::GetValue(keyName+subKey+\\shell\\open\\command, "", "-1")); if(reg == ""){ Registry::SetValue(keyName+subKey+"\\shell\\open\\command", "", exeFolder+"\\CLRTest.exe"); Registry::SetValue(keyName+"\\.gpj", "", subKey); Registry::SetValue(keyName+subKey+"\\DefaultIcon", "", exeFolder+"\\CLRTest.exe"); } 

So... any good programmatic way?
Thanks!

##### Share on other sites
What do you mean?

That is the programmatic way.

##### Share on other sites
If I understand the question, in the command line a %1 will expand to the file name that is being invoked.

Also, did you stick all those funky bracketed url strings in your code, or is that the forum software going crazy?

##### Share on other sites
Yes, sorry, it was the forum acting up, didn't let me write a double backslash without making it a URL, sorry about that =\

And I'm sorry that I wasn't very clear, I was rushed to errands, so I had to write this a little quickly.
What I meant, is that, yes, that is the programmatic way to set the values for the first time, so now each .gpj file on my system should be automatically opened with the program I set it to open with here, and have the same icon as that program, right?
But when I use this method to open a .gpj file with my program, the program would just crash, it, not only doesn't pass its' path as an argument, it makes the program not run, and I'm not quite sure why, as I can't debug when opening it by other means than the compiler...

I'm sorry if I'm still not very clear. =\

##### Share on other sites
Can you post what the generated registry entry looks like? Unfortunately I can't make heads or tails of it from the code since the forum beat the crap out of it...

##### Share on other sites
Sure, there you go.

As far as I can tell by looking at other applications, this seems to have worked smoothly enough though.

##### Share on other sites
As I said, you can use %1 in the command entry, which will expand into the file name. In general you wrap it in quotation marks so that it will be parsed as a single argument.

##### Share on other sites
No, I don't think that's it though...

Things is, this is my main function:
 int main(array<System::String ^> ^args) { // Enabling Windows XP visual effects before any controls are created Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); // Create the main window and run it if(args->Length > 0) Application::Run(gcnew Form1(args[0])); else Application::Run(gcnew Form1()); return 0; } 
Basicly, it's a Managed C++ form project, so I check if there are any arguments passed to the process when it starts, and if there are, I forward the path to an overloaded constructor for the main form of the project.
This works well when I put the path in the command arguments in Options->Debugging(VS2008) and debug from inside the compiler, but when I open the file using the program from outside the compiler it just crashes with the general "send/don't send error reports to Microsoft" error, so I don't think it's about parsing the argument.... Or am I getting it wrong?

##### Share on other sites
Try Application::Run(gcnew Form1(args[1])); instead. The first arguments is the filename of the executable, while the later are the passed arguments

##### Share on other sites
No, that part is actually right...
I know it's true in Native C++ that the first real argument is 1 and not 0, but apparently it's not the same in MC++.
Since when I change if(args->Length > 0) to if(args->Length > 1) and open the file with the program it'll go into the else case and use the default constructor, and since when I add the path in the command arguments field in the options it only has 1 argument still.
So this implies that there's only 1 argument passed, and that it is the one I need, but for some reason it just crashes the program, and I can't seem to get why...

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 23
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631733
• Total Posts
3001928
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!