0

I would like to use ShellExecute in my C++ program to force the opening of a tiff image with Windows Photo Viewer on W7 and W10. By default, tiff images are opened with another viewer on my machine. The goal is to have a flexible solution that will work no matter what is the default program used to open tiff images.

Running this in cmd.exe does what I need:

rundll32 "%ProgramFiles%\Windows Photo Viewer\PhotoViewer.dll", ImageView_Fullscreen C:\Temp\myimage.tif

Now, how would that translate in my ShellExecute parameters? I tried the following, but it does not work. Not sure if it's syntax or I am not sending the right parameters to the function.

ShellExecute(NULL, _T("open"), _T("rundll32 \"%ProgramFiles%\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen C:\\Temp\\myimage.tif"), NULL, NULL , SW_HIDE);

Thanks!

MiniG34
  • 312
  • 2
  • 12
  • Using rundll32 you might have better luck with CreateProcess: https://stackoverflow.com/questions/42531/how-do-i-call-createprocess-in-c-to-launch-a-windows-executable –  Mar 22 '19 at 15:18
  • If you insist on using ShellExecute then give it the full path to rundll32.exe as the third argument and move the rest of the command line to the fourth argument. –  Mar 22 '19 at 15:19
  • (the above is my best guess based on the documentation, I have no way to try it out at the moment) –  Mar 22 '19 at 15:26

1 Answers1

0

This works for me on Win 10

ShellExecute(
     NULL,                //-- hwnd
     "open",              //-- lpOperation
     "rundll32.exe",      //-- lpFile
                          //-- lpParameters
     "\"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen C:\\temp\\P1000325.jpg",
     NULL,                //-- lpDirectory
     SW_HIDE);            //-- nShowCmd
dmaelect
  • 151
  • 2
  • 14