Show
Ignore:
Timestamp:
04/08/09 15:11:27 (6 years ago)
Author:
robert
Message:

From Marc Sciabica, made searching of the install path for plugins option, and added the dll path to the search path under Windows

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgDB/FileUtils.cpp

    r9475 r9991  
    1818#if defined(WIN32) && !defined(__CYGWIN__) 
    1919    #include <io.h> 
     20    #define WINBASE_DECLARE_GET_MODULE_HANDLE_EX 
    2021    #include <windows.h> 
    2122    #include <winbase.h> 
     
    8788#define OSGDB_FILENAME_TEXT(x) L ## x 
    8889#define OSGDB_WINDOWS_FUNCT(x) x ## W 
     90#define OSGDB_WINDOWS_FUNCT_STRING(x) L ## #x L"W" 
    8991typedef wchar_t filenamechar; 
    9092typedef std::wstring filenamestring; 
     
    9496#define OSGDB_FILENAME_TEXT(x) x 
    9597#define OSGDB_WINDOWS_FUNCT(x) x ## A 
     98#define OSGDB_WINDOWS_FUNCT_STRING(x) #x "A" 
    9699typedef char filenamechar; 
    97100typedef std::string filenamestring; 
     
    649652        } 
    650653 
    651         //   2. The system directory. Use the GetSystemDirectory function to  
     654        //   2. The directory that the dll that contains this function is in. 
     655        // For static builds, this will be the executable directory. 
     656 
     657        // Requires use of the GetModuleHandleEx() function which is available only on Windows XP or higher. 
     658        // In order to allow execution on older versions, we load the function dynamically from the library and 
     659        // use it only if it's available. 
     660        bool addedDllDirectory = false; 
     661        OSGDB_WINDOWS_FUNCT(PGET_MODULE_HANDLE_EX) pGetModuleHandleEx = reinterpret_cast<OSGDB_WINDOWS_FUNCT(PGET_MODULE_HANDLE_EX)> 
     662            (GetProcAddress( GetModuleHandleA("kernel32.dll"), OSGDB_WINDOWS_FUNCT_STRING(GetModuleHandleEx))); 
     663        if( pGetModuleHandleEx ) 
     664        { 
     665            HMODULE thisModule = 0; 
     666            static char static_variable = 0;    // Variable that is located in DLL address space. 
     667 
     668            if( pGetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, &static_variable, &thisModule) ) 
     669            { 
     670                retval = OSGDB_WINDOWS_FUNCT(GetModuleFileName)(thisModule, path, size); 
     671                if (retval != 0 && retval < size) 
     672                { 
     673                    filenamestring pathstr(path); 
     674                    filenamestring dllDir(pathstr, 0,  
     675                                              pathstr.find_last_of(OSGDB_FILENAME_TEXT("\\/"))); 
     676                    convertStringPathIntoFilePathList(OSGDB_FILENAME_TO_STRING(dllDir), filepath); 
     677                    addedDllDirectory = true; 
     678                } 
     679                else 
     680                { 
     681                    osg::notify(osg::WARN) << "Could not get dll directory " 
     682                        "using Win32 API. It will not be searched." << std::endl; 
     683                } 
     684            } 
     685            else 
     686            { 
     687                osg::notify(osg::WARN) << "Could not get dll module handle " 
     688                    "using Win32 API. Dll directory will not be searched." << std::endl; 
     689            } 
     690        } 
     691 
     692        //   3. The system directory. Use the GetSystemDirectory function to  
    652693        //      get the path of this directory. 
    653694        filenamechar systemDir[(UINT)size]; 
     
    667708        } 
    668709 
    669         //   3. The 16-bit system directory. There is no function that obtains  
     710        //   4. The 16-bit system directory. There is no function that obtains  
    670711        //      the path of this directory, but it is searched. 
    671         //   4. The Windows directory. Use the GetWindowsDirectory function to  
     712        //   5. The Windows directory. Use the GetWindowsDirectory function to  
    672713        //      get the path of this directory. 
    673714        filenamechar windowsDir[(UINT)size]; 
     
    689730 
    690731 
    691         //   5. The current directory. 
     732        //   6. The current directory. 
    692733        convertStringPathIntoFilePathList(".", filepath); 
    693734 
    694         //   6. The directories that are listed in the PATH environment  
     735        //   7. The directories that are listed in the PATH environment  
    695736        //      variable. Note that this does not include the per-application  
    696737        //      path specified by the App Paths registry key.