I'm hooking CreateCompatibleDC function into single .NET 32bit application.
Problem is that, when I hook the function, the method that depends on that API crashes with NullReferenceException, even when I don't do anything specific, just call original API from callback. Here's the code:
Code: Select all
HBITMAP (WINAPI *CreateCompatibleDCNext)(_In_ HDC hdc);
HBITMAP CreateCompatibleDCCallback(_In_ HDC hdc)
{
return CreateCompatibleDCNext(hdc);
}
HookAPI("gdi32.dll", "CreateCompatibleDC", (PVOID)CreateCompatibleDCCallback, (PVOID*)&CreateCompatibleDCNext);
In the logs, I see this error:
I'm also hooking CoCreateInstance and it has same error. Any idea what am I doing wrong? I'm running latest version of MadCodeHook 3 on Windows 10 64bit.System.Drawing - Object reference not set to an instance of an object.
at System.Drawing.SafeNativeMethods+Gdip.GdipGetDC
at System.Drawing.Graphics.GetHdc
at System.Drawing.Graphics.CopyFromScreen
at System.Drawing.Graphics.CopyFromScreen
Thanks