Sunday, February 8, 2009

[VC++] Getting your application's module name

You can get your application module name through any of the below ways,
Using CWinApp::m_pszExeName
// This will return the application name (applicable for MFC application only)
AfxGetApp()->m_pszExeName;


Using GetModuleFileName()
char szAppPath[MAX_PATH] = "";
CString csAppName;// Assuming CString is supported else use std::string or so
::GetModuleFileName(0, szAppPath, MAX_PATH);
// Extract application name
csAppName = szAppPath;
csAppName = csAppName.Mid(csAppName.ReverseFind('\\') + 1);

No comments: