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 bu...@apache.org on 2001/09/18 01:53:26 UTC

DO NOT REPLY [Bug 3666] New: - Win32MsgLoader unable to retrieve error text if DLL is renamed

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=3666>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

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

           Summary: Win32MsgLoader unable to retrieve error text if DLL is
                    renamed
           Product: Xerces-C++
           Version: 1.5.1
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Utilities
        AssignedTo: xerces-c-dev@xml.apache.org
        ReportedBy: jerry.carter@speechworks.com


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