Need some help with Dlls

This is a discussion on Need some help with Dlls within the Windows Programming forums, part of the Platform Specific Boards category; How timely a problem, maybe this will help to find what part of the process is falling over....

  1. #16
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    How timely a problem, maybe this will help to find what part of the process is falling over.

  2. #17
    Registered User
    Join Date
    Aug 2007
    Posts
    19
    Ok, using the methods in the link above me, it seems that loading the 2nd dll also loads KERNEL32.dll, which then fails to load.

    The debugging I get from MSVC++ (i just copied the parts from starting to load testDll.dll to when it unloads it (and starts to load next dll). (testDll.dll is the 2nd dll I load, hence the one that fails; also note, if I load them in opposite order, the other dll will fail to load).

    Code:
    120c:1130 @ 02836191 - LdrpLoadDll - RETURN: Status: 0x00000000
    120c:1130 @ 02836191 - LdrLoadDll - RETURN: Status: 0x00000000
    120c:1130 @ 02836191 - LdrLoadDll - ENTER: DLL name: testDll.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft Visu
    120c:1130 @ 02836191 - LdrpLoadDll - ENTER: DLL name: testDll.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft Vis
    120c:1130 @ 02836191 - LdrpLoadDll - INFO: Loading DLL testDll.dll from path C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft Vi
    120c:1130 @ 02836191 - LdrpFindOrMapDll - ENTER: DLL name: testDll.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsof
    120c:1130 @ 02836191 - LdrpFindKnownDll - ENTER: DLL name: testDll.dll
    120c:1130 @ 02836191 - LdrpFindKnownDll - RETURN: Status: 0xc0000135
    120c:1130 @ 02836191 - LdrpSearchPath - ENTER: DLL name: testDll.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft 
    120c:1130 @ 02836191 - LdrpResolveFileName - ENTER: DLL name: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll
    120c:1130 @ 02836191 - LdrpResolveFileName - RETURN: Status: 0x00000000
    120c:1130 @ 02836191 - LdrpResolveDllName - ENTER: DLL name: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll
    120c:1130 @ 02836191 - LdrpResolveDllName - RETURN: Status: 0x00000000
    120c:1130 @ 02836191 - LdrpSearchPath - RETURN: Status: 0x00000000
    120c:1130 @ 02836191 - LdrpMapViewOfSection - ENTER: DLL name: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll
    'TestProjectForDll.exe': Loaded 'C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll', Binary was not built with debug information.
    120c:1130 @ 02836191 - LdrpMapViewOfSection - RETURN: Status: 0x40000003
    120c:1130 @ 02836191 - LdrpRelocateImage - ENTER: DLL name: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll
    120c:1130 @ 02836207 - LdrpRelocateImage - RETURN: Status: 0x00000000
    120c:1130 @ 02836207 - LdrpFindOrMapDll - RETURN: Status: 0x00000000
    120c:1130 @ 02836207 - LdrpHandleOneOldFormatImportDescriptor - INFO: DLL "C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll" imports "KERNEL32.dll"
    120c:1130 @ 02836207 - LdrpLoadImportModule - ENTER: DLL name: KERNEL32.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Mic
    120c:1130 @ 02836207 - LdrpFindOrMapDll - ENTER: DLL name: KERNEL32.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microso
    120c:1130 @ 02836207 - LdrpFindOrMapDll - RETURN: Status: 0x00000000
    120c:1130 @ 02836207 - LdrpLoadImportModule - RETURN: Status: 0x00000000
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0xcf for procedure "DeleteCriticalSection" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrGetProcedureAddressEx - INFO: Locating procedure "RtlDeleteCriticalSection" by name
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0xec for procedure "EnterCriticalSection" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrGetProcedureAddressEx - INFO: Locating procedure "RtlEnterCriticalSection" by name
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x12a for procedure "FindAtomA" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x160 for procedure "FreeLibrary" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x16b for procedure "GetAtomNameA" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x1fe for procedure "GetLastError" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x241 for procedure "GetProcAddress" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x2de for procedure "InitializeCriticalSection" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrGetProcedureAddressEx - INFO: Locating procedure "RtlInitializeCriticalSection" by name
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x2e8 for procedure "InterlockedExchange" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x2fb for procedure "IsDBCSLeadByteEx" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x32e for procedure "LeaveCriticalSection" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrGetProcedureAddressEx - INFO: Locating procedure "RtlLeaveCriticalSection" by name
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x331 for procedure "LoadLibraryA" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x35c for procedure "MultiByteToWideChar" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x480 for procedure "Sleep" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x495 for procedure "TlsGetValue" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x4bd for procedure "VirtualProtect" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x4bf for procedure "VirtualQuery" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpSnapThunk - WARNING: Hint index 0x4df for procedure "WideCharToMultiByte" in DLL "KERNEL32.dll" is invalid
    120c:1130 @ 02836207 - LdrpHandleOneOldFormatImportDescriptor - INFO: DLL "C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll" imports "msvcrt.dll"
    120c:1130 @ 02836207 - LdrpLoadImportModule - ENTER: DLL name: msvcrt.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Micro
    120c:1130 @ 02836207 - LdrpFindOrMapDll - ENTER: DLL name: msvcrt.dll DLL path: C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug;C:\Windows\system32;C:\Windows\system;C:\Windows;.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Nmap;C:\Program Files (x86)\Microsoft Visual Studio 10.0\;C:\Program Files (x86)\Microsoft
    120c:1130 @ 02836222 - LdrpFindOrMapDll - RETURN: Status: 0x00000000
    120c:1130 @ 02836222 - LdrpLoadImportModule - RETURN: Status: 0x00000000
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x34 for procedure "__dllonexit" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x3d for procedure "__lc_codepage" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x41 for procedure "__mb_cur_max" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0xb6 for procedure "_errno" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x10a for procedure "_iob" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x21a for procedure "_winmajor" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x247 for procedure "abort" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x253 for procedure "calloc" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x262 for procedure "fflush" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x26b for procedure "fprintf" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x26c for procedure "fputc" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x271 for procedure "free" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x279 for procedure "fwrite" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x27d for procedure "getenv" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x29f for procedure "localeconv" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x2a4 for procedure "malloc" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x2aa for procedure "memcpy" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x2b4 for procedure "puts" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x2d1 for procedure "strlen" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x2ec for procedure "vfprintf" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpSnapThunk - WARNING: Hint index 0x2f9 for procedure "wcslen" in DLL "msvcrt.dll" is invalid
    120c:1130 @ 02836222 - LdrpUpdateLoadCount2 - INFO: Referencing loaded DLL "C:\Windows\syswow64\msvcrt.dll" (new reference count: 0x2)
    First-chance exception at 0x7743e0ed in TestProjectForDll.exe: 0xC0000005: Access violation writing location 0x9cea9020.
    120c:1130 @ 02836222 - LdrpUpdateLoadCount2 - INFO: Dereferencing loaded DLL "C:\Windows\syswow64\msvcrt.dll" (new reference count: 0x1)
    120c:1130 @ 02836222 - LdrpUnloadDll - INFO: Unmapping DLL "C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll"
    'TestProjectForDll.exe': Unloaded 'C:\Users\Niklas\Documents\Visual Studio 2010\Projects\TestProjectForDll\Debug\testDll.dll'
    120c:1130 @ 02836222 - LdrpLoadDll - RETURN: Status: 0xc0000005
    120c:1130 @ 02836222 - LdrLoadDll - RETURN: Status: 0xc0000005
    Maybe someone with a bit more experience then me could see what is going on.

  3. #18
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    Windows will load as many DLLs as you tell it to provided it can find them. The default search path starts with the folder the binary is in and then proceeds to use the path environment variable. The search folder can be set with SetDllDirectory() (SetDllDirectory Function (Windows)).

    In my experience LoadLibrary() rarely, if ever, fails if it can find the DLL.

    That being said there are other issues in your code that could cause problems. You should define a pre-processor symbol that when set sets another symbol to __declspec(dllexport) and when not set sets it to __declspec(dllimport).

    Code:
    #ifdef MYDLL_EXPORTS
        #define MYDLL_DECL __declspec(dllexport)
    #else
        #define MYDLL_DECL __declspec(dllimport)
    #endif
    Use MYDLL_DECL in your declarations of all the functions and classes you wish to expose. Define the exports in the DLL project but do not define it in the project using the DLL. This will not fix your current problem but it will fix the problems you will encounter after you get the LoadLibrary() issues fixed.

  4. #19
    Registered User
    Join Date
    Aug 2007
    Posts
    19
    Quote Originally Posted by VirtualAce View Post
    That being said there are other issues in your code that could cause problems. You should define a pre-processor symbol that when set sets another symbol to __declspec(dllexport) and when not set sets it to __declspec(dllimport).

    Code:
    #ifdef MYDLL_EXPORTS
        #define MYDLL_DECL __declspec(dllexport)
    #else
        #define MYDLL_DECL __declspec(dllimport)
    #endif
    Use MYDLL_DECL in your declarations of all the functions and classes you wish to expose. Define the exports in the DLL project but do not define it in the project using the DLL. This will not fix your current problem but it will fix the problems you will encounter after you get the LoadLibrary() issues fixed.
    I did actually have that, but removed it to make it less to read for you all.

    By the way, I want to thank everyone who have tried to help so far, I really appreciate it.

  5. #20
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    What compiler are you building the dlls with? Their referencing msvcrt.dll instead of msvcr100.dll indicates it's a MinGW-alike (or you're using their libraries with VS 2010 or using the WDK). Also, what OS and SP are you running? Certainly is a strange error, looks like something is corrupting internal data structures, hence the dodgy pointer derefence before it calls your dll's DllMain.

    Might also be worth creating a dump file so we can get a proper picture of what the dilly-o is going on
    In Visual Studio (I use 2008 but they should be the same):
    Make the debugger complain on first chance exceptions (Debug menu -> Exceptions -> Win32 Exceptions -> Tick the c0000005 Access Violation box)
    Starting the project with debugging (F5)
    Clicking Break in the inevitable dialog
    And create a dump file (Open Task Manager -> Processes -> Right click the process -> Create Dump File)

    Compress the dump and upload it to rapidshare or yousendit or one of those sites.

    In other news:
    Code:
    bool APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
    Not that it should affect anything, but that first 'bool' wants to be 'BOOL'.

  6. #21
    Registered User
    Join Date
    Aug 2007
    Posts
    19
    I have compiled the exe with both MSVC++ 2010 and MinGW

    The Dll's are compiled with MinGW
    Oh, and I'm using Windows 7 Enterprise, SP1 I think

    I will create a dump file now.

    Edit: Ok, made the dump file, you can download it here(.zip) or here(.7z)
    Last edited by dumazz; 05-07-2011 at 05:51 PM.

  7. #22
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    612
    Looks like your version of MinGW has a problem with TLS sections and DLL relocations.
    Code:
    The good one
    631c0000 631cf000   2 (start, end, name of dll)
    Header info
    D000 [      18] address [size] of Thread Storage Directory (dll has TLS)
    
    0:000:x86> dd 631cd000
    These lot are the first part of a IMAGE_TLS_DIRECTORY32, these are pointers to bits in the dll
    631cd000  631cd019 631cd01c 631c9020 631cc004 (All nice and valid)
    
    The bad one, which has been relocated
    00030000 0003f000   testDll (start, end, name of dll)
    
    Header info
    D000 [      18] address [size] of Thread Storage Directory (dll has TLS)
    
    0:000:x86> dd 0x0003d000
    0003d000  9cead019 9cead01c 9cea9020 9ceac004 (oops, these are not only not pointing within the dll, they're not pointing in the valid address space)
    Windows then tries to write something to the incorrect address which causes the exception and unloads the dll.

    If you're not using the most recent version of MinGw that might fix it, otherwise apart from trying to avoid linking in their TLS bits, it seems like you're pretty short of luck.
    Last edited by adeyblue; 05-08-2011 at 08:43 PM.

  8. #23
    Registered User
    Join Date
    Aug 2007
    Posts
    19
    Hmm, that still doesn't explain to me why the first dll always loads successfully, but guess I have to upgrade MinGw then.

    Thank you all for all your help, I really appreciate it!
    Wish you the best of luck with your current and future programming projects.

    Thanks

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLLs in C++
    By RoshanX in forum C++ Programming
    Replies: 0
    Last Post: 02-22-2006, 12:48 PM
  2. DLLs
    By cgod in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 07:21 AM
  3. .dlls
    By alpha2018 in forum C++ Programming
    Replies: 2
    Last Post: 08-25-2004, 01:27 PM
  4. Use of DLLs
    By Supar in forum C++ Programming
    Replies: 7
    Last Post: 06-17-2003, 04:25 PM
  5. Using C DLLs in VB
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 10-10-2001, 03:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21