使用Explorer.exe打开文件夹
问题描述:
亲爱的,
我需要打开一个文件夹,我使用这段代码作为样本并且运行良好
Dear all ,
I need to Open a folder and i used this code as sample and its working well
PROCESS_INFORMATION ProcessInfo = {0};
STARTUPINFO StartupInfo = {0};
BOOL result =CreateProcess(_T("C:\\Windows\\explorer.exe"),
_T("/e,/root,F:\\Images\\Car\\AUDI"),
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&StartupInfo,
&ProcessInfo);
但是我需要传递文件夹路径所以我这样编码并且它没有用。可以修复它
but i need to pass the Folder path so i coded like this and it not worked.Can you Fix it
CString s0="F:\Images\Car\AUDI"; //s0="F:\Images\Car\AUDI"
CString s1=_T(" /e,/root,"); //s1="/e,/root,"
CString s2=s0+s1; //s2="/e,/root,F:\Images\Car\AUDI"
s2.Replace(_T("\\"),_T("\\\\")); // replace \ with \\
CString s3=_T("\"")+s2+_T("\""); // s3=""/e,/root,F:\\Images\\Car\\AUDI"" -added " "
LPWSTR pointer=(LPTSTR)(LPCTSTR)s3; //convertion
// Create the process
PROCESS_INFORMATION ProcessInfo = {0};
STARTUPINFO StartupInfo = {0};
BOOL result = CreateProcess(
_T("C:\\Windows\\explorer.exe"), // Module name.
pointer, // Command line.
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&StartupInfo,
&ProcessInfo);
谢谢
Jay
Thanks
Jay
答
将CString
转换为LPWSTR $时可能出错c $ c>在这一行:
There may be a error in convertingCString
toLPWSTR
in this line:
LPWSTR pointer=(LPTSTR)(LPCTSTR)s3; //convertion
尝试使用此代码:
Try using this code:
LPWSTR pointer = s3.GetBuffer();