Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute() file in same directory

Status
Not open for further replies.

nbgoku

Programmer
May 25, 2004
108
US
1.exe has the following code

ShellExecute(0, "open", "2.exe", NULL, NULL, SW_SHOWNORMAL);

1.exe and 2.exe are in the same directory

now this works cool only if i give the full path to 2.exe, but the thing is, the 2.exe is in the same directory as the .exe file im launching it from, so how do i code ShellExecute() to open 2.exe which is in the same directory without having to give the full path


 
I guess something like:
".\\2.exe"

Ion Filipski
1c.bmp
 
Obtain caller's module path in 1.exe and build full path of 2.exe for ShellExecute():
Code:
char path[_MAX_PATH];
GetModuleFileName(0,path,sizeof path); // curr module path
char* p = strrchr(path,'\\'); // where exe name pos...
strcpy(p+1,"2.exe"); // Now pass path to ShellExecute...
Be careful: No errors checking in my snippet...
It seems using .\ is not robust method because of no guarntee that current dir is the same as module (1.exe) dir. It seems it is the main source of your problem...
 
If you have the files in your DEBUG/RELEASE directory and you execute the program from dev studio, you may see it looking at the project folder and NOT the debug/release directories. I have noticed this when running in debug.

Matt
 
sweet thanks yall!


im curious though, has does a person go about finding information like using .\\ to mean the same directory?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top