How does 'Open With...' work?

  • Thread starter Thread starter Peter Oliphant
  • Start date Start date
P

Peter Oliphant

If I use 'Open With...' to open a file (menu option) and choose a program I
wrote, how do I write a MS C++ 2005 Express application to respond to this?

I tried doing this with a program of mine and I got a system error message
(crash). I would assume the filename would be one of the main( ) arguments,
but I'm just guessing. And not sure why it crashed. My program runs fine
ordinarily, and I would have thought trying to open a file with this way
should only run the program since it has no logic to deal with the argument
list. That is, why does it crash when doing this and not ignore the file and
just run?

Thanks in advance for any info!

[==P==]
 
Peter said:
If I use 'Open With...' to open a file (menu option) and choose a program I
wrote, how do I write a MS C++ 2005 Express application to respond to this?

I tried doing this with a program of mine and I got a system error message
(crash). I would assume the filename would be one of the main( ) arguments,
but I'm just guessing. And not sure why it crashed. My program runs fine
ordinarily, and I would have thought trying to open a file with this way
should only run the program since it has no logic to deal with the argument
list. That is, why does it crash when doing this and not ignore the file and
just run?

Peter:

Open With works by placing entries in the HKCU registry. These entries
override any entries placed in HKCR. However the mechanism for passing
the document filename to the indicated application is the same.

What is happening to you exactly?
 
Haven't really put much work into this. But I just tried the experiment of
using an application I created (which is totally unaware of 'Open With') to
try to open a graphic file, and it returned a system error (i.e., the
program crashed).

I'm not in any need or hurry to use this feature, but in the future it might
be somewhat convenient. I'm creating an application that creates pixel data
based on an an image obtained from a file, so opening such a file with the
application directly would save a step (but certainly isn't necessary for my
application)...

[==P==]
 
Peter said:
Haven't really put much work into this. But I just tried the experiment of
using an application I created (which is totally unaware of 'Open With') to
try to open a graphic file, and it returned a system error (i.e., the
program crashed).

Peter:

Well, your application must be prepared to open a file of the desired
type. If it is an MFC doc-view application it should be all set up so
that if your app can open a file using File->Open, it will also open it
from the shell (though perhaps using a new instance, if you have not
taken steps to avoid this).
 
Peter Oliphant said:
If I use 'Open With...' to open a file (menu option) and choose a program
I wrote, how do I write a MS C++ 2005 Express application to respond to
this?

I tried doing this with a program of mine and I got a system error message
(crash). I would assume the filename would be one of the main( )
arguments, but I'm just guessing. And not sure why it crashed. My program
runs fine ordinarily, and I would have thought trying to open a file with
this way should only run the program since it has no logic to deal with
the argument list. That is, why does it crash when doing this and not
ignore the file and just run?

You are correct that it should be provided as a command line argument.

As for why the app crashes, could it because the working directory is
different? If the program uses private DLLs or loads any files from the
"current" directory it might not find them when run using Open With.
Thanks in advance for any info!

[==P==]
 
"As for why the app crashes, could it because the working directory is
different? If the program uses private DLLs or loads any files from the
"current" directory it might not find them when run using Open With."

Bingo! THAT's why it didn't work! Thanx! :)

[==Peter==]

Ben Voigt said:
Peter Oliphant said:
If I use 'Open With...' to open a file (menu option) and choose a program
I wrote, how do I write a MS C++ 2005 Express application to respond to
this?

I tried doing this with a program of mine and I got a system error
message (crash). I would assume the filename would be one of the main( )
arguments, but I'm just guessing. And not sure why it crashed. My program
runs fine ordinarily, and I would have thought trying to open a file with
this way should only run the program since it has no logic to deal with
the argument list. That is, why does it crash when doing this and not
ignore the file and just run?

You are correct that it should be provided as a command line argument.

As for why the app crashes, could it because the working directory is
different? If the program uses private DLLs or loads any files from the
"current" directory it might not find them when run using Open With.
Thanks in advance for any info!

[==P==]
 
Back
Top