Monday, November 19, 2007

Getting the current application path

Have u ever confronted with the need of getting the path of the current application? One method is of course to use the function GetModuleFileName(). But there is another easier method. It is figured out below:

In Win32 application, you can get to the program name through the variable __argv. You can just reference __argv directly. It is declared in stdlib.h

Test this out by adding the following simple line in your application:

   MessageBox( NULL, __argv[0], "App Path", MB_OK ); 

No comments: