How are Win32 types represented in C # P / Invoke?

I am trying to call the PrintDlgW Win32 API from C # through P / Invoke. With P / Invoke Interop Assistant 1.0 from Microsoft, I can declare the necessary data structures and import functions from the DLL. But how to use HDC or HWND in C #? Thanks in advance.

+6
c # interop pinvoke
source share
3 answers

This site has nice examples with structures already defined for quite a few APIs. The structure is here .

+2
source share

HWND in C ++ is indeed void *, which is presented in C # as IntPtr.

+4
source share

It can make it easier.

  using HWND = System.IntPtr;

Then use HWND in your pInvoke ... to make it easier to read and keep it β€œthe same” as the pin code signature.

Hope this helps, Regards, Tom.

+1
source share

All Articles