CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Andrew Truckle Guest

    [RESOLVED] Application's directory

    I've used the following to get my dialogs application directory:

    CString gPath;

    GetModuleFileName(NULL, gPath.GetBuffer(_MAX_PATH), _MAX_PATH);
    gPath.ReleaseBuffer();

    gPath = gPath.Left(gPath.ReverseFind('\\') + 1);


    Is this the best way?



  2. #2
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    100

    Re: Application's directory

    Hi! Andrew. It's me again.
    I am not sure what exact U want to do.
    But if ur want to find the directory
    of ur app. How about GetCurrentDrectory()?

    Good luck with your Work!

    Walter




  3. #3
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    100

    Re: Misspell

    Sorry for misspelling!

    It's GetCurrentDirectory()!!!


    Walter


  4. #4
    Andrew Truckle Guest

    Re: Misspell

    Yes, but surely, isn't it possible that a user may adjust the "start up directory" of their short-cut which would change the current directory from that of where the program actually resides?


  5. #5
    Andrew Truckle Guest

    Re: Misspell

    Hi Walter

    I tried GetCurrentDirectory()

    It returned c:\video instead of c:\video\debug which is where the exe is.


  6. #6
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    100

    Re: Misspell

    Did you run your App from VC IDE or
    your App?

    As I try if U ran ur App in VC IDE,
    it chopps \debug. But if run from ur
    App, I believe it will show full path.

    Try again if U didn't.



    Walter



  7. #7
    Andrew Truckle Guest

    Re: Misspell

    Hi Walter

    I think you are right.

    I've ended up not using this code anyway since I've added the AVI file as a resource.

    But atleast I know the principle of how to get the directory. But, suppose someone modifies the properties of a short-cut to the program where they change the "startup directory", will it still return the programs location?

    Regards


  8. #8
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    Re: Misspell

    Hi Andrew,

    GetCurrentDirectory will always return the current directory, as the name says. This means, if someone sets the working directory to another dir, it will return this. Or if you use the common file dialog, it will change the current directory by default.

    Your first attempt with GetModuleFileName was correct.


    Martin

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