使用Explorer.exe打开文件夹 [英] Open a Folder Using Explorer.exe

查看:396
本文介绍了使用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 在这一行:

There may be a error in converting CString to LPWSTR in this line:
LPWSTR pointer=(LPTSTR)(LPCTSTR)s3; //convertion



尝试使用此代码:


Try using this code:

LPWSTR pointer = s3.GetBuffer();


这篇关于使用Explorer.exe打开文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆