 -  // keep the internal refcount at +1.
 -  if (!OpenedHandles->insert(a_handle).second)
 -    FreeLibrary(a_handle);
-+void CloseLibraryImpl(void *dlHandle) {
-+  FreeLibrary((HMODULE)dlHandle);
++bool CloseLibraryImpl(void *DlHandle, std::string *ErrMsg) {
++  if (!FreeLibrary((HMODULE)DlHandle)) {
++    MakeErrMsg(ErrMsg, std::string(Filename) + ": Cannot close: ");
++    return false;
++  }
++  return true;
 +}
  
 -  return DynamicLibrary(a_handle);
-+void *GetAddressOfSymbolImpl(void *dlHandle, const char *symbolName,
-+                               bool Global) {
-+  if (dlHandle == &OpenedHandles) {
++void *GetAddressOfSymbolImpl(void *DlHandle, const char *SymbolName,
++                             bool Global) {
++  if (DlHandle == &OpenedHandles) {
 +    // Dummy library that represents "search all handles".
 +    if (Global) {
-+      // All libraries are already being searched.
++      // All libraries are already being searched, do not recurse.
 +      return 0;
 +    } else {
-+      // Perform a global symbol search.
-+      DynamicLibrary::SearchForAddressOfSymbol(symbolName);
++      // Perform a global symbol search through all libraries.
++      DynamicLibrary::SearchForLibrarySymbol(SymbolName);
 +    }
 +  }
-+  return (void *)(intptr_t) GetProcAddress((HMODULE)dlHandle, symbolName);
++  return (void *)(intptr_t) GetProcAddress((HMODULE)DlHandle, SymbolName);
  }
  
 -// Stack probing routines are in the support library (e.g. libgcc), but we don't

+    return &OpenedHandles;
   }
   
   HMODULE a_handle = LoadLibrary(filename);
 
   if (a_handle == 0) {
     MakeErrMsg(errMsg, std::string(filename) + ": Can't open : ");
-    return DynamicLibrary();
+    return NULL;
   }
 

+
+#undef EXPLICIT_SYMBOL
+}
