开发者

GetDC() DllImport for x64 apps

If you make a little research on the internet you'll see many DLLImport styles for this user32.dll function:

HDC GetDC(HWND hWnd);

The question is: what type is more appropriate for .NET x64 apps (either compiled with the Platform target as AnyCPU on a x64 machine or specifically as x64)? IntPtr for example grows to a size of 8 on a x64 process, can this be a problem? Is uint more appropriate than Uint64? What is the size of the pointers this function uses when used in a x64 process? The DLL is called user32.dl开发者_如何学Pythonl does it work as 32bit or 64bit on a x64 operating system?

[DllImport("user32.dll",EntryPoint="GetDC")]
public static extern IntPtr GetDC(IntPtr hWnd);
public static extern uint GetDC(uint hWnd);
public static extern int GetDC(int hWnd);

Thanks!


You should represent handles (including HDC and HWND) by IntPtr. This still works on a x64 system: although IntPtr is 8 bytes and the DLL is called User32.dll, the handle size still matches the IntPtr size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜