0

I have a problem with running PhotoViewer on image file with spaces in its path.

I'm using C++ function CreateProcess, supplying a command line as its argument. The command line template for that is:

"rundll32 <path to PhotoViewer.dll> ImageView_Fullscreen <path to image> "
e.g.
"rundll32 \"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen Z:\\Documents\\Projects\\ScreenCapture1\\ScreenCapture\\ScreenCapture\\sample.bmp"

The problem here is the fact that must be without double quotes and cannot contain spaces.

My code is more or less like this

_tcscpy_s( str, 200, _T("rundll32 \"C:\\Program Files\\Windows Photo Viewer\\PhotoViewer.dll\" ImageView_Fullscreen Z:\\Documents\\Projects\\ScreenCapture1\\ScreenCapture\\ScreenCapture\\sample.bmp") );
CreateProcess( NULL,            // No module name (use command line). 
        str,            // Command line. 
        NULL,           // Process handle not inheritable. 
        NULL,           // Thread handle not inheritable. 
        FALSE,          // Set handle inheritance to FALSE. 
        0,              // No creation flags. 
        NULL,           // Use parent's environment block. 
        NULL,           // Use parent's starting directory. 
        &si,            // Pointer to STARTUPINFO structure.
        &pi );          // Pointer to PROCESS_INFORMATION structure.

HANDLE hProcess = pi.hProcess;
CloseHandle(hProcess);

Now I want to run PhotoViewer on an image file with spaces on its path, for example

C:\the folder\has spaces\the image file.bmp

1 Answers1

1

Use the old windows style paths if there is spaces in them with a tilde.

For example,

c:\thefol~1\hasspa~1\theima~1.bmp
Mark
  • 11
  • 1
  • 1
    @poolie: Use GetShortPathName (https://msdn.microsoft.com/en-us/library/windows/desktop/aa364989.aspx). But a short style path name is not always available, it can be disabled by the system admin. – dalle Dec 12 '16 at 07:49