Launching application under windows with launch

I noticed that I can run the program using the associated handler by writing the initial filename . However, for some files, all I get is the console and I don't know why. I am trying to populate a list box control in MFC and I want the program and its associated handler to run when I double-click a selection. Is there a better way or explanation why this doesn't work?
This is the code that might be the problem:


int selection = listControl.GetCurSel();
CString text;
listControl.GetText(selection,text);
string std_str = StringUtils::CStringToString(text);
string st = string("start \"")+std_str+string("\"");
const char* command = st.c_str();
system(command);

      

+1


source to share


2 answers


If the first parameter on the command line is start

enclosed in double quotes, it uses that as the window title instead of the command. It is lame, but what does it do ...

Try

string st = string("start \"\" \"")+std_str+string("\"");

      



instead.

But if you are trying to get a wrapper handler for a file to execute from your process, the best and cleaner way to do this instead of calling a command start

is to use ShellExecute()

either the ShellExecuteEx()

Win32 API.

+5


source


I believe start uses the file handler associated with the file extension.

Basically it will use the file extension to find which application to launch.
It looks like the extension for the files you are using results in the default console startup handler.



You can start by reading the MS documentation:
http://msdn.microsoft.com/en-us/library/53ezey2s.aspx

+1


source







All Articles