Archived

This topic is now archived and is closed to further replies.

CProgrammer

alternative to system()

Recommended Posts

I am making a starter program and i need a function call that opens an exe file. I know one can use system() but i was wondering wether there is a function call that opens the exe directly without an MS-DOS window. -CProgrammer

Share this post


Link to post
Share on other sites
Ok i used ShellExecute in my app which worked fine.
However say im executing "Data/app.exe" when i do this the application app.exe assumes that it is in the same directory as the primary application it is however in ''Data''. All Data that app.exe now loads like "settings.ini" would need to be renamed to "Data/settings.ini" which in this case is not an option.
How can i solve this problem?

Share this post


Link to post
Share on other sites
Never open files with a relative path unless you have a good reason to. Always build a complete absolute path.

Use GetModuleFileHandle( NULL ) and remove your exe file name.
Use that path for opening your files from. It may be a bit more work to do but it pays off. You can call your app any possible way and it will find it''s files.

(Note: Talking Windows here)

Share this post


Link to post
Share on other sites
So am i getting this right?
I can''t find GetModuleFileHandle but assume GetModuleHandle will give me the path of the exe running.
So if i append for instance "Data/app.exe" to the string after truncating the exe file part i have the absolute path.
Now if i use ShellExecute with the absolute address my app will find its files?
Well i tryed writng the entire path into the code by hand and it didnt work. Maybe you could explain this in a bit more detail.
Thanks
-CProgrammer

Share this post


Link to post
Share on other sites
I was thinking more in the way of the app to be called should do this with every file it opens (this applies of course only if you can change the code).
Otherwise try to set the path you get from GetModuleHandle() (sorry, my mistake before) as the 5th parameter of ShellExecute
(which should set the current working directory for the app).

Share this post


Link to post
Share on other sites