views:

399

answers:

1

Hi All, I have an application that loads few image files from "images\" folder relative to the location where the application is located. Can anybody let me know how do I get the location in Visual C++. A quick google search revealed, there is no straightforward way. Can anybody help me to solve this ?

Thanks DM

+1  A: 

Use GetModuleFilename() to get the complete path of the application and chop off the executable name:

    wchar_t appPath[ MAX_PATH ];
    memset( appPath, 0, MAX_PATH * sizeof( wchar_t ) );

    wchar_t modulePath[MAX_PATH];
    if ( GetModuleFileName( NULL, modulePath, MAX_PATH ) > 0 )
    {
        wchar_t *lastBackSlash = wcsrchr( modulePath, '\\' );
        if ( lastBackSlash )
        {
            memcpy( appPath, modulePath, ( lastBackSlash - modulePath ) * sizeof( wchar_t ) );
        }
    }
Volker Voecking