Opened 11 years ago

Last modified 9 years ago

#5211 closed defect

LoadLibrary error check is not quite correct. — at Initial Version

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

Description

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 (0)

Note: See TracTickets for help on using tickets.