CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Posts
    14

    Accessing an applications executable path...

    I want to know how to programmatically get hold of the Path of the MFC program i have written. I can get access to the current application name, but i want the entire path of the executable.

    What i want to achieve is that, when a user run my application, i want to know the entire path from where the application is being launched. Tried the variable present in the CWinApp class, but not able to get the Path. Tried looking in Win32 API, but still couldn't converge on one if present.


    Any suggestions ?
    Thanx
    Mahanthi



    [email protected]

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Accessing an applications executable path...

    Try GetModuleFileName()

    Regards,

    Paul McKenzie


  3. #3
    Join Date
    May 1999
    Location
    Belgium
    Posts
    37

    Re: Accessing an applications executable path...

    try using the string:

    _pgmptr

    this will give you the application path

    Hope this helps,

    Steven


  4. #4
    Join Date
    Apr 1999
    Posts
    18

    Re: Accessing an applications executable path...

    Try using the following function call:

    GetCurrentDirectory (sizeof (g_aEXELocation),
    g_aEXELocation);


    Hope this helps.


  5. #5
    Join Date
    Apr 1999
    Posts
    14

    Re: Accessing an applications executable path...

    Hi,
    Thanks, it was helpful. It did work and this was the function i was looking for.

    Thanks once again.
    Mahanthi


    [email protected]

  6. #6
    Join Date
    May 1999
    Posts
    26

    Re: Accessing an applications executable path...


    GetCurrentDirectory () will not give you the application exe path if you have a different Start-in directory.

    You should use GetModuleFileName() as follows:

    char chExePath[_MAX_PATH];
    GetModuleFileName(GetModuleHandle(NULL), chExePath, _MAX_PATH);

    HTH




  7. #7
    Join Date
    May 1999
    Posts
    24

    Re: Accessing an applications executable path...

    Guys,

    Just call GetCommandLine() function

    and you'll receive full path to .exe name and all parameters.

    Thanks,
    Ilgar Mashayev

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured