Fog Creek Software
Discussion Board

This should be Easy ...

VC++ (really windows) question:

I've got some legacy code that saves a file and then launches notepad.  It's pretty simple:

char szCommand[_MAX_PATH];
lstrcpy(szCommand,"NOTEPAD.EXE ");
WinExec(szCommand, SW_SHOWNORMAL);

Because NotePad is always in the path.

Now, I've changed the file to CSV.  Excel is no longer in the path, but in Windows, if I double-click on the .CSV, it'll launch Excel.  However, if I just send the string "C:\filename.csv" to winExec, it doesn't launch excel.

Worse, excel isn't in the path.  And if I hard-code:

C:\Program Files\Microsoft Office\Office\Excel.exe - even IF it works on all modern versions of office, it won't work on machine where the user customized the install.

I've look at office automation on CodeGuru/Project, but the article were poorly written.  This should be trivial, what am I missing?

Any advice?  Ideas?  Links to articles?  I -know- this should be easy ...

Matt H.
Thursday, January 9, 2003

I forgot exactly where I did this, but I believe that ShellExec (or ShellExecute?) would do it.  If the file type is registered, it will work.

Thursday, January 9, 2003

Yes, I concur ShellExecute. It does exactly what you want.

On a related note, when I type "Excel" into the Run box, it runs Excel even though I can't find Excel anywhere in my Path.

Anyone know how they pulled off that trick?

Thursday, January 9, 2003

I believe they use a registry entry for both the Run from command line and for the binding.  Run regedit and you will see an entry under HKEY_LOCAL_MACHINE for the .xls that specifies to use excel

Adam Young
Thursday, January 9, 2003

actually it's from the "App Paths" section of the registry where you can specify a path for each application.

Joel Spolsky
Thursday, January 9, 2003

Try CreateDispatch function to open EXCEL.

Thursday, January 9, 2003

You guys Rock!


Matt H.
Thursday, January 9, 2003

Try to use ShellExecute instead.

Friday, January 10, 2003

*  Recent Topics

*  Fog Creek Home