# CodeGuru Technical FAQs > CodeGuru Individual FAQs >  Visual C++ Application: How to get the applications name?

## Andreas Masur

*Q:* How to get the application name?

*A:* If this is a MFC application you could do



```
AfxGetApp()->m_pszExeName;
```

In all other cases the function 'GetModuleFileName()' can be used...



```
// With STL string
#include <string>

char        szAppPath[MAX_PATH] = "";
std::string strAppName;

::GetModuleFileName(0, szAppPath, MAX_PATH);

// Extract name
strAppName = szAppPath;
strAppName = strAppName.substr(strAppName.rfind("\\") + 1);



// With CString
char    szAppPath[MAX_PATH] = "";
CString strAppName;

::GetModuleFileName(0, szAppPath, MAX_PATH);

// Extract name
strAppName = szAppPath;
strAppName = strAppName.Right(strAppName.ReverseFind('\\') + 1);
```

----------

