Hi All,
I have a C++ program( using VC++6.0 with MFC) which calls another C++ .exe and performs some actions on it. The problem I am facing is that I get the file name of the .exe by using a GetDirectory function. Thus I am able to get the full file name such as "C:\projectname\software\debug\something.exe". Next I am trying to use the ShellExecute function to use this file name in the parameters such as ShellExecute(NULL,"open" ,"PatternName", NULL, NULL, SW_SHOWNORMAL); where PatternName is "C:....." . This doesn't give any errors but just that the .exe doesn't open! I realised that if I use double slash in the file name it works fine. But since I get the file in the above format(with single slash) I am unable to do that. Is there any workaround?As far as the filename is concerned I am only able to break it into drive,dir,filename(debug), ext using splitpath.
I cannot give the file name directly because diff user save the file in diff locations and we need to change the path in each of their pgms which is not viable option.
Any help is appreciated..
Thanks in advance
Recommended Answers
Jump to PostIt sounds to me Krisny that you've got to parse the file name apart returned from your directory obtaining function and insert the "\\" characters the compiler wants to see in the string you feed into ShellExecute(). Afterall, you said it works if you feed in a correctly specified path, …
Jump to PostWhat about replacing the backslashes with forward slashes?
So wherever there was a single backslash, replace it with a forward slash. That should also fix your problem!I know typically in Windows, filepaths look like this:
C:\SomeDirectory\SomeFile.extBut in C++ forward slashes are also acceptable for file paths..
…
All 5 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.