You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jerry Carter <je...@speechworks.com> on 2001/09/11 21:32:37 UTC

Why does Xerces_DLLName exist on Win32?

My complements to the Xerces development team on the 1.5.1 release.  You've
produced an excellent XML parser with impressive multiplatform support.
The one bug that I've found in 1.5.1

  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3422

was already fixed in the development tree before I noticed it.  This second
issue has proved to be a subtle bug in our integration with Xerces relating
to the Xerces_DLLName.  Please consider this change for the next version.
[If Bugzilla is the preferred venue for change requests, just let me know
and I'll create a new entry.  Thanks.]

---------

Searching through the 1.5.1 code base, this macro is defined for several
compilers but only used in two places.

  src/util/MsgLoaders/Win32/Win32MsgLoader.cpp and
  src/util/Platforms/Tandem/TandemPlatformUtils.cpp

For Windows, the DLL name is used to get a handle to the current module
(i.e. the Xerces DLL) so that error messages may be loaded.  This is
unnecessary and introduces a subtle dependency - if the DLL is renamed, the
error messages can no longer be retrieved!

Instead, we can define a global module handle.

  HINSTANCE globalModuleHandle;

This is safe.  The module handle cannot change during the process lifetime.
 When the DLL is loaded, the handle is passed as an argument to DllMain.

  BOOL APIENTRY DllMain(HINSTANCE hModule,
                        DWORD  ul_reason_for_call,
                        LPVOID lpReserved)
  {
    switch (ul_reason_for_call) {
    case DLL_PROCESS_ATTACH:
      globalModuleHandle = hModule;
      break;
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
      break
    }
    return TRUE;
  }

The Win32MsgLoader class can then use the global handle without using the
hardcoded DLL name.

  Win32MsgLoader::Win32MsgLoader(const XMLCh* const msgDomain) :

      fDomainOfs(0)
      , fModHandle(0)
      , fMsgDomain(0)
  {
      // Try to get the module handle
      fModHandle = globalModuleHandle;
      ...

With this change, the DLL may be renamed, repackaged, or otherwise mangled
while preserving the error messages.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org