none
Windows 7 - LoadLibrary() fails (32bit) - why?

    Question

  • Windows 7 - LoadLibrary() fails (32bit) - why?

    We have encountered a strange problem, that is currently unique to Windows 7.
    No other OS currently did cause a problem with this DLL so far. The DLLs are
    pure C compiled with complete static libraries and only use native Win32 API.
    (no MFC stuff).

    The scenario is this:
    an EXE dynamically loads DLL1, which dynamically loads DLL2.

    DLL1 has imports from KERNEL32, USER32, GDI32.
    DLL2 has imports from KERNEL32, USER32, ADVAPI32.

    (EXE)
    - LoadLibrary (DLL1) => SUCCESS
    - - LoadLibrary (DLL2) => FAILURE => GetLastError => 998
      
    We were testing with different setups:

    (EXE)
    - LoadLibrary (DLL2) => SUCCESS

    (EXE)
    - LoadLibrary (DLL3) => SUCCESS
    - - LoadLibrary (DLL2) => SUCCESS
     
    Error 998 reads "access violation", so I hooked up a debugger to get some information
    where an access violation might happen (first chance exeptions are caught by the
    debugger). But no access violation happened - the LoadLibrary simply fails with 998.
    Putting a MessageBox into the DLLEntryPoint function showed, that this function
    is not called, when the LoadLibrary fails.

    I google'd regarding possible causes and I found a topic which mentioned
    corrupted/bad relocation tables. But why did the DLL2 work without any
    problem on other Windows versions?

    Then I compiled DLL2 with two different compilers, to get different relocation
    tables. But the problem persisted.

    Then I compiled DLL1 with a different compiler and now the inital setup worked.
    BUT why? As long as the true reason, why DLL1 causes the error is unknown
    I'm very concerned about potential problems that might happen randomly, if I
    need to add code to DLL1. And playing around with different compilers to
    randomly fix this problem is not acceptable.

    Anybody ever had similar problems? What might cause the error 998 except for
    the mentioned access violations? 

    Any help is appreciated.

    Regards
      Andy
    Monday, October 19, 2009 2:16 PM

All replies

  • AWAe have a similar problem, except we get error code 487, invalid address.  The problem does not occur with Server 2008 64-bit, but with Windows 7 64-bit.  If we try to delay-load most of our dll's we get the error, but if we load them first, they work.  We allow the dll's to be relocated but the ones that fail do not relocate.  We checked the address where they were to load and the debugger says the memory is not in use.
    Tuesday, January 05, 2010 10:09 PM