Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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:
[code]
exeFolder = Environment::CurrentDirectory;
String^ keyName = "HKEY_CURRENT_USER\\Software\\Classes";
String^ subKey = [url="file://\\SilverBridge.Phantasya"]\\SilverBridge.Phantasya[/url];
//Registring the file extension if not already registered
String^ reg = Convert::ToString(Registry::GetValue(keyName+subKey+[url="file://\\shell\\open\\command"]\\shell\\open\\command[/url], "", "-1"));
if(reg == ""){
Registry::SetValue(keyName+subKey+"[url="file://\\shell\\open\\command"]\\shell\\open\\command[/url]", "", exeFolder+"[url="file://\\CLRTest.exe"]\\CLRTest.exe[/url]");
Registry::SetValue(keyName+"[url="file://\\.gpj"]\\.gpj[/url]", "", subKey);
Registry::SetValue(keyName+subKey+"[url="file://\\DefaultIcon"]\\DefaultIcon[/url]", "", exeFolder+"[url="file://\\CLRTest.exe"]\\CLRTest.exe[/url]");
}
[/code]

So... any good programmatic way?
Thanks!

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


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

Things is, this is my main function:
[code]
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;
}
[/code]
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 this post


Link to post
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 [code]if(args->Length > 0)[/code] to [code]if(args->Length > 1)[/code] 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...

Share this post


Link to post
Share on other sites
Wow, yea ><
That's it, thanks alot. The error wasn't with passing the path, it was somewhere later in the code that didn't work with this path.

Thanks =\

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this