- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Have you ever been in the position of having written a DLL that is incorporated into a Windows Forms application that has no console window....
... and all the diagnostic trace code requires console output.
While it is simple to create a console inside your code of the DLL, what do you do when the error your are trying to trace out occurs at DLL load time prior to entry into Main of your forms application?
I recently had come upon this situation. My DLL depended upon a 3rd party DLL that had load issues. Fortunately, their DLL had an option switch, enabled by environment variable, that would dump out diagnostic information to the console. Unfortunately when there is no console, this information gets lost.
The solution is to create the console at the time of LoadDLL that is called inside the runtime system initialization phase at program load time. To do this you add a startup routine, typically referred to as DllMain.
function DllMain (hInstDLL, fdwReason, lpReserved) !DEC$ ATTRIBUTES STDCALL, DECORATE, DLLEXPORT, ALIAS:"DllMain" :: DllMain USE IFWINTY USE Kernel32 IMPLICIT NONE integer(BOOL) :: DllMain integer(HANDLE), intent(IN) :: hinstDLL integer(DWORD), intent(IN) :: fdwReason integer(LPVOID), intent(IN) :: lpReserved character(500) :: eVar logical, save :: FirstTime = .true. integer(BOOL) :: b if(FirstTime) then FirstTime = .false. b = AllocConsole() write(*,*) "***************************" CALL GET_ENVIRONMENT_VARIABLE("MIC_LIBRARY_PATH",eVar) write(*,*) "MIC_LIBRARY_PATH=",TRIM(eVar) CALL GET_ENVIRONMENT_VARIABLE("MIC_LD_LIBRARY_PATH",eVar) write(*,*) "MIC_LD_LIBRARY_PATH=",TRIM(eVar) write(*,*) "***************************" flush(6) DllMain = 1 else DllMain = 0 endif end function DllMain
In my situation, an additional environment variable had to be set to enable the other DLL's trace output. This worked to get the information we needed to start the investigation of offload failure.
Jim Dempsey
Link Copied

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page