Click here to Skip to main content
15,917,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to find while loading a cpp dll from an exe whether that dll is retuning false from DllMain method

Suppose I have an cpp exe and internally it is trying to load a cpp dll ,then if the cpp dll return false from DllMain method

What I have tried:

I have checked on the internet but no luck
Posted
Updated 13-May-19 6:53am

 
Share this answer
 
Comments
Coder969 11-May-19 11:26am    
Thanks for the response. I have checked the link .I am facing an applicatio crash intermittently with ERROR_DLL_INIT_FAILED . I have a c# project which loads a managed cpp dll. managed Cpp dll will load a third party native cpp dll (not using load library function to load the native cpp dll , using header file and the lib file). While creating the object for the managed cpp dll then C# application is throw exception with error code 1114. From the error, can I assume that native dll dllmain function is returning false?
Richard MacCutchan 11-May-19 11:34am    
You can assume anything you wish, but that is not a good way to diagnose problems. You should use the debugger to trace exactly where, and hopefully why, the error is being generated.
Coder969 11-May-19 11:48am    
I am doing the debugging and in the meantime posted the question to get some clues :)
Richard MacCutchan 11-May-19 11:50am    
Without more information it is impossible to suggest anything more.
Coder969 12-May-19 6:02am    
Sorry for not posting the original error. I thought that might be the issue from a dllMain function in one of my dll.

My application is crashing intermittently . I have done the debugging through windbg and it is showing the error in clr .Below is the logging from windbg

FAULTING_IP:
clr!GetMetaDataInternalInterfaceFromPublic+25e75
6e7256fa f70000000080 test dword ptr [eax],80000000h

EXCEPTION_RECORD: ffffffff -- (.exr 0xffffffffffffffff)
ExceptionAddress: 6e7256fa (clr!GetMetaDataInternalInterfaceFromPublic+0x00025e75)
ExceptionCode: c0000005 (Access violation)
ExceptionFlags: 00000000
NumberParameters: 2
Parameter[0]: 00000000
Parameter[1]: 6bd15370
Attempt to read from address 6bd15370

FAULTING_THREAD: 00000c8c

DEFAULT_BUCKET_ID: INVALID_POINTER_READ

PROCESS_NAME: application.exe

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.

EXCEPTION_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%08lx referenced memory at 0x%08lx. The memory could not be %s.

EXCEPTION_PARAMETER1: 00000000

EXCEPTION_PARAMETER2: 6bd15370

READ_ADDRESS: 6bd15370

FOLLOWUP_IP:
clr!GetMetaDataInternalInterfaceFromPublic+25e75
6e7256fa f70000000080 test dword ptr [eax],80000000h

MOD_LIST: <analysis>

NTGLOBALFLAG: 70

APPLICATION_VERIFIER_FLAGS: 0

MANAGED_STACK:
SP IP Function
00000000 00000001 App_config_1a0000!Application.Read()+0x2
002EF438 0040174B App_config_1a0000!Application.Re()+0xc3
002EF460 00400081 App_config!Application.Main()+0x31

StackTraceString: <none>
HResult: 8007045a

EXCEPTION_OBJECT: !pe 18f41f8
Exception object: 018f41f8
Exception type: System.IO.FileLoadException
Message: Could not load file or assembly 'ManagedCPP.dll' or one of its dependencies. A dynamic link library (DLL) initialization routine failed. (Exception from HRESULT: 0x8007045A)
InnerException: <none>
StackTrace (generated):
SP IP Function
00000000 00000001 App_config_1a0000!Application.Read()+0x2
002EF438 0040174B App_config_1a0000!Application.Re()+0xc3
002EF460 00400081 App_config!Application.Main()+0x31

From the windbg logging, I have seen access violation from clr and after that it is showing dll loading issues. Is it because clr crash the dll is not loading?
Problems with dll are often resulting with dependencies to other dlls, This is known as "dll hell". So welcome ;-)

I would recommand using the tool dependency walker. This great tool helped me in a lot of crazy scenarios and solved my headaches. Pay attention to x32 and x64 flavor of this tools (and your dlls)

profi-tip: using static linking as often as possible and check that the dlls are in the search path or in the correct directory which also should be starting directory of the process.

The mantra is: user dlls are in the installation-directory of the app, but system or third party dlls ware installed with the installation software of the vendor.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900