Opened 11 years ago

Closed 9 years ago

#5211 closed defect (fixed)

LoadLibrary error check is not quite correct.

Reported by: damiandixon Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: 1.10.0
Severity: minor Keywords:
Cc:

Description (last modified by Even Rouault)

The Microsoft KB111610 (http://support.microsoft.com/kb/111610) shows that you should check the return value from LoadLibrary as follows:

    pLibrary = LoadLibrary(pszLibrary);
    if( pLibrary <= (void*)HINSTANCE_ERROR )
    {
        return NULL;
    }

This affects two files: gbgetsymbol.cpp, cplgetsymbol.cpp.

The reason for this change is that if a DLL or one of its dependencies does not exist then a MessageBox is usually (though not always) displayed by Windows.

To suppress the display of the MessageBox in an application we normally call SetErrorMode(SEM_NOOPENFILEERRORBOX|SEM_FAILCRITICALERRORS). The setting of SEM_FAILCRITICALERRORS is recommended by Microsoft. Sadly the default value is 0.

Setting SetErrorMode as we do will cause LoadLibrary to return a non-zero return value when an error occurs.

In neither of these situations is this an issue as GetProcAddress will subsequently fail.

I would suggest that allowing MessageBoxes to be displayed in situations such as command line tools or in applications should be avoided if at all possible as it may block valid processing.

The case we ran into is having some of the GDAL/OGR DLL plugins built but the 3rd party libraries they were dependent upon not present. In this case when registering the drivers the MessageBox was displayed (test code with out SetErrorMode called).

Change History (2)

comment:1 by Even Rouault, 11 years ago

Description: modified (diff)

Suggestiong applied in trunk (r26356)

comment:2 by Jukka Rahkonen, 9 years ago

Resolution: fixed
Status: newclosed

As Even wrote, applied in trunk and also followed by r27460:

Windows plugin: complementary fix to #5211 to avoid error dialog box when there are dependency problems (#5525). Closing as fixed.

Note: See TracTickets for help on using tickets.