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

Started by
5 comments, last by HalfAftamat 19 years, 11 months ago
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?
Advertisement
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
tj963
10x
but i dont understand how can i figure out which file in the directory is the exe file?
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.
The first command line argument passed to a program is the name of the file.
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.
>> 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.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

This topic is closed to new replies.

Advertisement