How can I get my program to grab a string containing its own pathname so that I can enter it in the Registry? (It has to be an absolute path name--i.e., c:\install\myprog\myprog.exe, not just myprog.exe)

I tried AfxGetApp()->m_pszAppName and got an invalid pointer (Debug assertion failed when I tried to run it). Even using this->m_pszAppName came up with a null string (I used MessageBox(NULL,this->m_pszAppName,"Filename",MB_ICONINFORMATION) to test).

This is for a Windows program that is being written from scratch, so it can't be a case of Microsoft deciding that they know better than I do what I want to do. (Well, it can, but it's far less likely than it would be with the AppWizard)