The program I'm messing with has builtin logging. Using a proxy DLL, I managed to activate it by calling the right functions from the real DLL. However, I got stuck at using the actual logging functions, as the program crashes with Error 0xC0000142 whenever I get close to using them.
Here's what I'm doing in my proxy DLL:
typedef void (*FDLAddr_t)(void);
FDLAddr_t ForceDebugLog;
typedef void (*LIAddr_t)(char const *, ...);
LIAddr_t LogInfo;
void setupFuncs() {
HMODULE trueDll= GetModuleHandleA(".\\trueDll.dll");
ForceDebugLog = (FDLAddr_t)GetProcAddress(trueDll, "?ForceDebugLog@@YAXXZ");
// LogInfo = (LIAddr_t)GetProcAddress(trueDll, "?LogInfo@@YAXPBDZZ");
}
Now, I can just do ForceDebugLog();
and logging gets enabled. However, as soon as I uncomment the LogInfo
line, the program crashes on startup with Windows showing the error 0xc0000142.
Further experimentation shows that GetProcAddress
returns the address of LogInfo
in the DLL. Also, the line appears to be fine if LogInfo
was a FARPROC
, as that works without a problem. As soon as I add the cast to LIAddr_t
, the error comes back.
How can I work around this issue? Or do I need to take a different approach? All binaries involved are 32 bit.