#### Archived

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

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

## Recommended Posts

HalfAftamat    122
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 on other sites
tj963    234
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 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 on other sites
Zipster    2365
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 on other sites
Guest Anonymous Poster
The first command line argument passed to a program is the name of the file.

##### Share on other sites
Zipster    2365
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 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 itaccess() to make sure you''ve got the exerealpath() to get full path / resolve symlinks on *nixchdir 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.