Objective
To make troubleshooting easier for the technicians who are deploying our software into a production environment, I would like our Windows service to log any DLLs that it cannot load/locate at run-time when the service starts. Nothing fancy, just:
- name of DLL
- success / failure
This is easy enough for DLLs that are explicitly loaded (e.g. using LoadLibrary()
). Unfortunately I have no idea how to do this for DLLs that are loaded automatically when the application starts (i.e. implicitly loaded DLLs).
In otherwords, how do you detect DLLs that are being statically loaded at run-time? Is this even possible?
Any guidance you can provide would be greatly appreciated!
Additional Context
- Test Machine: Windows 8.1 Enterprise (64bit)
References
- MSDN: Linking an Executable to a DLL
- Implicit & Explicit Linking
- MSDN: Using Run-Time Dynamic Linking
- MSDN: LoadLibrary function
- MSDN: Dumpbin /Dependents
- Example:
DumpBin.exe /Dependents c:\Path\To\Application.exe
- Example:
Updates
Update1
To make things as easy as possible for the deployment team, I had hoped to write a clear message to the application's event log MyWindowsService.log
(after all, that is where they look for all of the other messages)... but to Mark Segal's point, a Windows Event Log entry is created:
Faulting application name: MyWindowsService.exe, version: 2.7.4.1, time stamp: 0x55673caa
Faulting module name: ImplicitlyLoadedLibrary.dll, version: 6.3.9600.17736, time stamp: 0x550f42c2
Exception code: 0xc0000135
Fault offset: 0x0009d4f2
Faulting process id: 0x168c
Faulting application start time: 0x01d0997fc49e50fe
Faulting application path: C:\Program Files (x86)\CompanyName\ApplicationName\MyWindowsService.exe
Faulting module path: ImplicitlyLoadedLibrary.dll
Report Id: 024adcd5-0573-11e5-830a-6c198fb1a83d
Faulting package full name:
Faulting package-relative application ID:
For anyone who is interested Exception code: 0xc0000135
means:
A dependent dll was not found
Update 2
The original intent was to see if:
- Can you check for dependencies before the loader begins it's job, or
- Can you hook into the loading process to see what DLLs are being loaded
While it is true I could implement an entirely new loading mechanism (i.e. think plug-in architecture), that would be way beyond the scope of what I had wanted to accomplish.
From the answers thus far, it doesn't appear like 1.
or 2.
are possible.