I have a weird problem in one of my projects lately regarding the Win32 API ShellExecute()
function.
The program is compiled using Visual C++ 2015, in ANSI mode.
int ret = (int)ShellExecuteA(0, "open", "C:\\Users\\Maverick\\stratum.jpg", NULL, NULL, SW_SHOWNORMAL);
printf("ShellExecute return value: %i\n", ret);
In the above code, ShellExecute()
returns 42, so it should be successful. However, it doesn't actually open the file.
I don't have privilege problems, and it fails with the same problem even when running the program as an administrator.
In fact, I can successfully run the file this way:
system("C:\\Users\\Maverick\\stratum.jpg");
I don't want to be forced to use system()
, though.
Also, before I migrated the project to a newer Visual Studio, I was using Visual C++ 6.0, and the code worked fine.
Any clues what may be the problem?
EDIT: ShellExecuteEx()
also returns successful (1), but does not open the file.
SHELLEXECUTEINFO ShExecInfo;
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "C:\\Users\\Maverick\\stratum.jpg";
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOWNORMAL;
ShExecInfo.hInstApp = NULL;
int ret = (int)ShellExecuteExA(&ShExecInfo);