I’m trying to get the local ‘Program files’ dir path and append some extra path to it and simply execute it. Can’t get it to work properly..
This is my current code:
wchar_t* localAppData = 0;
SHGetFolderPath(NULL, CSIDL_PROGRAM_FILESX86, 0, NULL, &localAppData);
wstringstream ss;
ss << localAppData << L"/MyApp/MyExe.exe";
CreateProcess(static_cast<void*>(localAppData));
I’m getting this for teh SHGetFolderPath:
cannot convert parameter 5 from wchar_t ** to LPWSTR
Also, even though I’ve included sstream in the headers, I’m getting these errors:
'wstringstream' : undeclared identifier
Note: I’m using SHGetFolderPath as I need this to work on both XP and Vista/7
EDIT:
Had a mistake in the code above, I was trying to run localAppData which is the path to the ‘Program Files’ directory, instead of running the entire path.
But when I try using the ss var instead of localAppData var in the CreateProcess function, I’m getting an error about using the wrong type of var (need to be using LPCWSTR).
But when I try this, doesn’t work as well.. No error but application is not running, what am I missing?
wchar_t localAppData[MAX_PATH];
STARTUPINFO sInfo;
PROCESS_INFORMATION pInfo;
SHGetFolderPath(NULL, CSIDL_PROGRAM_FILESX86, 0, NULL, localAppData);
std::wstringstream ss;
ss << localAppData << L"/MyApp/MyExe.exe";
LPCWSTR str = ss.str().c_str();
CreateProcess(str, NULL,NULL, NULL,FALSE,NULL,NULL,NULL,&sInfo,&pInfo);
return str;
Any ideas?
SHGetFolderPath requires pointer to caller-allocated array, and fills it with resulting path.
Don’t forget about std namespace.