Saving and Loading Files
In my graphics application, I have a class that deals with saving and loading files and I've created my own extension .x . I have a method in that class that takes the name of a file, opens it, reads it and generates a particular scene according to the syntax I've defined previously. But the thing is: I don't want to change my code every time I want to open a different file!
Here's what I have already done: I have associated my new .x extension to the executable in question. What I want to know is how to pass my file's name to my executable the minute I doubleclick it.
I have a feeling it has something to do with the arguments in
Thanks for your help.
int main(int argc, char **argv)
Using int main parameters are only going to get you as far as being able to say what file you want as part of your shortcut. The best way, is either use a dialog from what ever GUI library you are using and ask on startup, or compile with the command window still there, and ask there.
I'm not quite sure if I completely understood what you've said, but I didn't want to have to type my file name every time I used my application. I wan't to use it like you'd use MSWord, for instance. When you doubleclick your file, the Operational System selects that application to be executed, and in addition makes it read and generate that file.
It would solve my problem if I could pass my file name as the argument **argv in main, when I doubleclicked the file. With this at hand, I could easily open, read and generate it using my application...
I hope I was clear enough.
(Assuming you are using Windows) Double-click the file with filename X. Select application to open. Tick "Always use this program", select your app, and OK.
Yeah, that's what I have already done (according to my first message). The thing is: in my code I need to know the filename to be able to use:
With what you just told me, I would be only running my app, without using my filename, thus not opening it. I need to know how to pass my filename as an argument of my main when I doubleclick it, just like in any other respectable app...
argc -> Number of arguments passed to your app (including the filename of your exe).
argv -> A 2D array of arguments passed to your app.
argv -> Array of the filename of your program.
argv -> First argument passed to your exe.
argv -> Second argument passed to your exe.
I found out that argv will be the filename when you doubleclick the file with the extension associated to your executable. That shall do it!