// JP opened flex table

Click to See Complete Forum and Search --> : Executable finding out its own filename/location


Tim the Furnish
December 29th, 2002, 12:54 PM
Hi -

Coming close to finishing an adventure game for Win32, now fiddling with making autorun stuff for the CD version. Got it all working properly - stick the CD in and it launches a program to automatically check whether game's been installed already. If not, it launches the installer found in the root of the CD. Lovely. However, if you click on a standard desktop link to the CD drive the checker program is launched with the current directory set to the desktop, not to the CD root. It runs OK, just fails to find anything on the CD (i.e. the installer) because the current directory is C:\blah\blah... not D:\, E:\, F:\, whatever (E and F in my case).

So... anyone know any way for an executable to work out where it was run from? (Whoever's bright idea it was to get rid of the information in the change from main to WinMain, I hate you!)

Changing the default directory in the actual CD drive shortcuts fixes the problem, of course, but that's no good. Or is this just yet another WinXP bug - when you create a shortcut to a CD drive the default directory should be filled in and isn't?

Any ideas for a workaround would be appreciated.

mdmd
December 29th, 2002, 01:31 PM
Hi Tim,

I think GetModuleFileName() is what you are looking for. This will give you the whole path that the specified application module is running from; NULL for the exe.

Tim the Furnish
December 29th, 2002, 04:07 PM
Bingo! Thanks a lot, works like a charm.

Loet
December 30th, 2002, 11:45 AM
.

//JP added flex table