Executable finding out its own filename/location

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.
[1198 byte] By [Tim the Furnish] at [2007-11-18 0:32:35]
# 1 Re: Executable finding out its own filename/location
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.
mdmd at 2007-11-9 13:02:27 >
# 2 Re: Executable finding out its own filename/location
Bingo! Thanks a lot, works like a charm.
Tim the Furnish at 2007-11-9 13:03:29 >