[SOLVED] win32 double-click-file-to-open-corresponding-app functionality

Started by
5 comments, last by esr_ever 16 years, 2 months ago
Hello all, Sorry for the topic title but I couldn't describe it better.. I want to make a console application in win32, which when I click on a specific file ( with it's type associated of course ), it should open the application & get the file path in order to process the file. If I drag the file on the application icon in the explorer, it loads & gets the filename in argv[1], but when I do it as I described in the beginning, it doesn't work.. Does anybody know anything about this?? Thanks in advance, babis [Edited by - esr_ever on January 31, 2008 9:02:51 PM]
Advertisement
It's done with file associations. When you double-click a file, explorer checks to see what program is set up to handle files of that type (By checking the file extension). If it doesn't find one registered, it'll ask the user what they want to do.
This sort of thing is done by setting up various registry entries, which should be done by your application's installer. If you don't have an installer, then you'll have to do the file association manually (Which I wouldn't recommend), and make sure you unregister it correctly too (Otherwise you'll annoy the hell out of your users if they end up with broken file associations because they've removed your app).

Do you want to do this when the app is run for the first time? Do you have an installer? Is setting up the assication manually not acceptable (I.e. selecting your app when Explorer asks you what app you want to open the file with)?
You might want to have a look at ShellExecute

Good luck
First of all, thanks for your answers, but unfortunately, neither seems to be what I'm looking for.

Evil steve, I only intend to run the app on my pc so I don't care about registry entries, I've already associated the file type with my executable, but when I double click a file of that type, it crashes, & I guess without going far in the app ( I have a cout right in the beginning of main()). But it does run better, (printing the cout, that is), when I drag a file on my executable.

Buklenios, ShellExecute seems to just use explorer's functionality on a file. If I understood correctly, it's just a code version of right click & action, so it isn't what I'm looking for.
Double clicking a file should have the exact same effect as dragging the file onto your exe, with the possible difference that the working directory could be different.

What crashes? Your app or explorer? And what's the exact error message you get? Have you tried this with an app that does nothing but display the contents of the command line passed to it when run?
My app was crashing.. I wrote a mini program, and you're right, both have the same effect, so it's probably my code's fault. The error is "The application has requested the runtime to terminate in an unusual way. blah blah". I guess I'll have a second look at it..
The application was called from a different directory, so with SetCurrentDirectory worked like a charm ( I loaded necessary files from it's directory). So, problem solved,thanks!

This topic is closed to new replies.

Advertisement