Archived

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

HalfAftamat

getting the name of the exe file(vc++)

Recommended Posts

I''m developing a game and i want to make a big exe file contains all the textures and sounds. so i created a little program that copies one file to the end of another. i paked all my textures and sounds and combined them with the exe file. the problem comes when i change the name of the exe. in the source code i wrote fopen("exename.exe","rb") so if i change the name of the exe i need 2 change the source code. how can i solve this problem?

Share this post


Link to post
Share on other sites
First, I''d suggest you either include the files as resources or keep them in separate files. Virus scanners may complain when you access your own executable. Have siad that, I use GetCurrentDirectory (WIN32 API) and tack on whatever filename I want. It seems to work as long as the caller isn''t in a separate thread from WinMain.

tj963

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
10x
but i dont understand how can i figure out which file in the directory is the exe file?

Share this post


Link to post
Share on other sites

TCHAR fileBuffer[_MAX_PATH];
GetModuleFileName(NULL, fileBuffer, _MAX_PATH);
// fileBuffer now contains the full path of the module (EXE/DLL)


And I second what the first poster said, don''t attach all your resources onto the EXE file. Have separate files.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
The first command line argument passed to a program is the name of the file.

True, but it''s only the filename, which can be a problem if the current directory changes. Also, scoping issues would mean you either have to pass the filename down through your function calls from WinMain/main, or store it globally. If you only need to get it once though, no need to store it globally.

Share this post


Link to post
Share on other sites
>> The first command line argument passed to a program is the name of the file.
> True, but it''s only the filename, which can be a problem if the current directory changes.
Only if called from a batch file; otherwise, you get the whole path.
If you want to be portable, it''s a little bit more work than GetModuleFileName:

take argv[0]
if win32: if .exe extension missing, add it
access() to make sure you''ve got the exe
realpath() to get full path / resolve symlinks on *nix
chdir to something relative to that


quote:
Also, scoping issues would mean you either have to pass the filename down through your function calls from WinMain/main, or store it globally. If you only need to get it once though, no need to store it globally.

You wouldn''t believe all the crap the CRT pulls into your app. __argv is one of the more useful things.

Share this post


Link to post
Share on other sites