Jump to content

  • Log In with Google      Sign In   
  • Create Account


Passing file name to main with Windows "open with" option


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 NotTakenSN   Members   -  Reputation: 149

Like
0Likes
Like

Posted 07 March 2013 - 03:09 AM

I would like to be able to right click on a file, such as a jpg, and open it with my application under the "open with" menu in Windows. How do I get the filename and directory to be passed along to the arguments in main (or winmain, since my app has a graphics interface)?

 

RIght now, my application has a predefined directory that it reads from. It executes fine when I double click the executable, but when I try opening my application under the "open with" drop down menu from a random file, I get an invalid allocation size error. My current code doesn't actually use any of the command line arguments to winmain, so why am I getting this error? Shouldn't it just launch the same way as when I double click my executable?



Sponsor:

#2 turch   Members   -  Reputation: 590

Like
2Likes
Like

Posted 07 March 2013 - 12:34 PM

Shouldn't it just launch the same way as when I double click my executable?

When your application is launched by an "open with", the current working directory is %WINDIR%\system32, so if you use any relative file paths they will be broken.

How do I get the filename and directory to be passed along to the arguments in main (or winmain, since my app has a graphics interface)?

It will be the first argument passed in to the application.

#3 Khatharr   Crossbones+   -  Reputation: 2974

Like
0Likes
Like

Posted 07 March 2013 - 07:47 PM

http://msdn.microsoft.com/en-us/library/windows/desktop/ms633559(v=vs.85).aspx


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#4 Endurion   Crossbones+   -  Reputation: 3498

Like
1Likes
Like

Posted 08 March 2013 - 02:26 AM

Play safe:
 
Use GetModuleFileName to fetch your executable file name.

Remove the file name.

Use the resulting path to create absolute paths for every file access you have.


Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS