Search code examples
c++handleloadlibrary

LoadLibrary() file path


I'm trying to use the function LoadLibrary(...) which takes in a string to a filename (.dll or .exe) or a filepath. The issue I'm having is when the filename itself has multiple periods/dots.

Example:

HINSTANCE hInst = LoadLibrary(_T("..\\folder\\file.name.dots.exe"));

The handle is always null and I cannot simply change the filename in this case. Microsoft mentioned multiple periods in https://support.microsoft.com/en-ca/kb/324468 but I don't believe it works for the filename. Any ideas?


Solution

  • As suggested in the referenced article, always compute fully-qualified path and pass that to LoadLibrary/LoadLibraryEx(). Not only does this work around the dot defect, it prevents a security vulnerability. Highjacking the current directory for your application can cause your app to run arbitrary code.

    See MSDN on LoadLibraryEx for a better understanding of the complexities of using LoadLibrary.