An MFC application generated using the Project Wizard of the VS2005 by default uses a Unicode character set for the project. If you are using __argv to access the command line arguments this might cause an application crash.

The following code illustrates the problem:

// Get the full path of the executable
char szAppPath[MAX_PATH];
strcpy_s(szAppPath, MAX_PATH, __argv[0]);

In the Unicode configuration __argv is set to NULL. Therefore using __argv[0] causes a crash. Actually, __argv is a pointer to a table of command line arguments of regular char type.

In order to access the command line arguments in argv style in Unicode applications, you should use __wargv – a wide character equivalent of __argv.

So your code may look like this:

wchar_t wszAppPath[MAX_PATH];
wcscpy(wszAppPath, __wargv[0]);

If you don’t need the Unicode encoding in your project, just change the Character Set to Not Set in the Configuration Properties | General.

You can also use GetModuleFileName Win API function to retrieve the fully-qualified path of the application.