Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all ,

I need to Open a folder and i used this code as sample and its working well

C++
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);



Thanks

Jay
Posted
Updated 22-May-14 6:47am
v2
Comments
[no name] 22-May-14 22:54pm    
Why not you try to debug it? If the first code works well why did you wrote the second one?
aboutjayesh 23-May-14 1:25am    
I debugged it.But the 2nd code not open the path specified.I prefer the second code because i would like to change the directory according to the request..

1 solution

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

Try using this code:
C++
LPWSTR pointer = s3.GetBuffer();
 
Share this answer
 
Comments
aboutjayesh 23-May-14 3:21am    
There is no Error,The 2nd code working and only opens the My computer Panel That displayed all the drives but when i hard code the folder path it getting opened :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900