Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

PInvoke.Gdi32.CreateCompatibleDC throws a MissingMethodException #427

Closed
CRogos opened this issue Feb 6, 2019 · 0 comments
Closed

PInvoke.Gdi32.CreateCompatibleDC throws a MissingMethodException #427

CRogos opened this issue Feb 6, 2019 · 0 comments
Labels

Comments

@CRogos
Copy link

CRogos commented Feb 6, 2019

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);           
}
@AArnott AArnott added the bug label Feb 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants