Sign in to follow this  
esr_ever

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

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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)?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites

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