Jump to content
  • Advertisement

Archived

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

CProgrammer

alternative to system()

This topic is 5492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
exec()?
CreateProcess()?

Depends whether you want to use windows or POSIX..

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!