dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

PInvoke.Gdi32.CreateCompatibleDC throws a MissingMethodException #427

Closed CRogos closed 4 years ago

CRogos commented 5 years ago

When the method "PInvoke.Gdi32.CreateCompatibleDC" is called, a MissingMethodException is thrown with the message ".ctor"

public static User32.SafeDCHandle CreateCompatibleDC(User32.SafeDCHandle hDC); I assume that the return value cannot be converted into a SafeDCHandle, because the window handle is not availble.

I would suggest to change the method signature to: public static IntPtr CreateCompatibleDC(User32.SafeDCHandle hDC);

The following work around is working:

var hdcSrc = GetWindowDC(windowHandle);
var hDest = MyGDI32.CreateCompatibleDC(hdcSrc.DangerousGetHandle());
var hdcDest = new SafeDCHandle(windowHandle, hDest);

class MyGDI32
{
            [DllImport("gdi32.dll")]
            public static extern IntPtr CreateCompatibleDC(IntPtr hDC);           
}