Home Forums Programming retrieve ull path to c++ executable

Welcome to our forums. These forums were active from 2003-2014. We have now decided to close them down, but will leave them here as an archive.

Remember you can send us feedback, news, jobs and content ideas by clicking here.

If you're really stuck for time, email news@gamedevelopers.ie.

You can also follow us on Twitter @gamedev_ie 

 

 

This topic contains 3 replies, has 3 voices, and was last updated by  Ro_Akira 11 years, 4 months ago.

  • Author
    Posts
  • #5187

    y2kprawn
    Participant

    Hi there,

    I have a C++ program which I need to get the full path to as I need to store game assets in a datbase. I am connecting via odbc so need ot make a DSN string. Now, I have it working but I need to put a literel path into the database string, which is in the same directory as the executable.
    If I change the place the .exe is , which i routinely do, I need to change the conenction string.
    So I was looking for a C++ windows API call which returns the path of the directory of the executable.
    Can anyone shed any light on this , any google search I make returns lots of USELESS results ?
    Cheers in advance guys and gals,
    Rob

  • #30653

    y2kprawn
    Participant

    Well , time is a great heler, unless you have a bad rash, then get a cream.
    And lo and behold the problem solution was found

    #include <direct.h> // for getcwd

    char FilePath[_MAX_PATH]; // _MAX_PATH represents the longest possible path on this OS

    getcwd(FilePath, _MAX_PATH); // reads the current working directory into the array FilePath

    works well for C++ in both VS6 and Bloodshed Dev c++.
    post closed.

  • #30877

    Eoin
    Participant

    In C and C++ applications argv[0] is set to the executables path. If you’re using C++, I highly recomend boost (boost.org) and its filesystem libraries.

  • #32959

    Ro_Akira
    Participant

    It can be extracted from the string returned by the Win32 function GetCommandLine () also.

The forum ‘Programming’ is closed to new topics and replies.