[AD] get_executable_name() in Windows |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi again,
Allegro's get_executable_name() uses GetCommandLine() in Windows. Why?
According to the function's description, it should fill buffer with full path
to the current executable. The Win32 API has a function called
GetModuleFileName() that does exactly this. As you can see in the example code
below, using this would be much simpler than parsing the output of
GetCommandLine() that is currently being done in 4.1.1.
Furthermore, it will work in cases were the current implementation will not.
If I run the code below from a command prompt in Windows XP; the current
implementation returns no path, while the Windows version returns full path.
Maybe there is a reason for not using GetModuleFileName() that eludes me (my
knowledge of the Win32 API is very limited); if not, please consider using it,
or change the documentation to reflect that you're not guaranteed to get the
full path in Windows.
Unrelated to this, I found a bug: When run from same dir in Windows XP, '.exe'
is stripped from name, but when run from short-cut on desktop, it is not.
Here is the code I used to test:
#include <allegro.h>
#include <winalleg.h>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
allegro_init();
install_timer();
install_keyboard();
char
caAl[1024],
caWin[1024];
get_executable_name(caAl, sizeof(caAl));
GetModuleFileName(0, caWin, sizeof(caWin));
cout
<< "Allegro: " << caAl << endl
<< "Windows: " << caWin << endl;
readkey();
}
END_OF_MAIN();
It was compiled with MinGW 2.0.0, and linked against Allegro 4.1.1 static
march=i586.
--
Sincerely,
Daniel Schlyder