Question

ShellExecute(NULL, TEXT("open"), TEXT("report\index.html"), NULL, NULL, SW_SHOWNORMAL);

Above is my line of code and I, for some reason, cannot get the file to open. Below are all the lines I have tried.

ShellExecute(NULL, TEXT("open"), TEXT("report/index.html"), NULL, NULL, SW_SHOWNORMAL);

ShellExecute(NULL, L"open", L"report\index.html", NULL, NULL, SW_SHOWNORMAL);

ShellExecute(NULL, _T("open"), _T("report\index.html"), NULL, NULL, SW_SHOWNORMAL);

Below is list of what I have included.

// Windows Header Files:
#include <windows.h>

// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

#include <Shellapi.h>

My file structure is structured out like this:

Downloads/test/program.exe
Downloads/test/report/index.html

This is the first time writing this code and I'm really not sure when to tell when I need to differentiate between "/" and "\". I believe I need to be using TEXT() because when I go to my VS2010 project, Properties > Character Set it says: Use Unicode Character Set. Or at least I believe I have to use TEXT(), I am really not sure.

Also do I need to provide the full path of the file instead of making the assumption it's traveling from where my exe is located? If so is there a quick and easy function call to get the full directory path? Is it just an include file I am missing?

Was it helpful?

Solution

If you are passing an hardcoded path, the path must be Windows style, with backslashes, and of course the backslash must be twice to escape it.

ShellExecute(NULL, TEXT("open"), TEXT("report\\index.html"), NULL, NULL, SW_SHOWNORMAL);

If you are using not a full path, you must of course make sure that the path is actually reachable, from the current working directory of your application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top