    if (a_handle == 0) {
 -    MakeErrMsg(errMsg, std::string(filename) + ": Can't open : ");
 -    return DynamicLibrary();
-+    MakeErrMsg(ErrMsg, std::string(Filename) + ": Can't open : ");
++    MakeErrMsg(errMsg, std::string(Filename) + ": Can't open : ");
 +    return NULL;
    }
  
 -  if (OpenedHandles == 0)
 -    OpenedHandles = new DenseSet<HMODULE>();
-+  return (void *) a_handle;
++  return (void *)a_handle;
 +}
  
 -  // If we've already loaded this library, FreeLibrary() the handle in order to

     // When no file is specified, enumerate all DLLs and EXEs in the process.
     if (OpenedHandles == 0)
-      OpenedHandles = new DenseSet<HMODULE>();
+      OpenedHandles = new DenseMap<void *, unsigned>();
 
     EnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0);
     // Dummy library that represents "search all handles".

-    FreeLibrary(a_handle);
+bool CloseLibraryImpl(void *DlHandle, std::string *ErrMsg) {
+  if (!FreeLibrary((HMODULE)DlHandle)) {
+    MakeErrMsg(ErrMsg, std::string(Filename) + ": Cannot close: ");
+    return false;
+  }
+  return true;
