Visual C++ Application: How to get the applications name?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: Visual C++ Application: How to get the applications name?

Hybrid View

  1. #1
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Visual C++ Application: How to get the applications name?

    Q: How to get the application name?

    A: If this is a MFC application you could do

    Code:
    AfxGetApp()->m_pszExeName;
    In all other cases the function 'GetModuleFileName()' can be used...

    Code:
    // 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);
    Last edited by Andreas Masur; July 24th, 2005 at 05:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center