我在路径中有空格的图像文件上运行 PhotoViewer 时遇到问题。
我正在使用 C++ 函数 CreateProcess,提供一个命令行作为它的参数。命令行模板是:
"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"
这里的问题是必须没有双引号并且不能包含空格。
我的代码或多或少是这样的
_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);
现在我想在路径上有空格的图像文件上运行 PhotoViewer,例如
C:\the folder\has spaces\the image file.bmp