You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library offers static generations of P/Invoke for all languages using custom MSBuild tasks to build CsWin32 generations from metadata.
It uses custom PowerShell scripts and MSBuild tasks to build libraries, and is attached to a CD workflow that publishes the packages on NuGet.
You can then use the packages just as you would with CsWin32, but installing the correct package (relevant to the link library) to get the correct information, or installing the 'aggregate' package that contains all the Win32 P/Invoke methods and supporting types generated from the Win32 metadata repo.
The best way to consume Win32 P/Invoke APIs via this collection of libraries is by using the built-in alias system.
Since all P/Invoke APIs across all packages generate into the same Windows.Win32.PInvoke class, you must use the correct alias to reference the correct version of the PInvoke class to call the P/Invoke APIs for that API set (DLL).
For example, the following extract performs the SetPixel function from gdi32.dll:
externaliasgdi32;// important: you must reference the appropriate alias for the API you are callinggdi32::Windows.Win32.Graphics.Gdi.HDCcontext=new(nint.Zero);// the hdc (device context) parameter in SetPixelintx=1;// the x coordinate parameter in SetPixelinty=1;// the y coordinate parameter in SetPixelgdi32::Windows.Win32.Foundation.COLORREFwhite=new(0x00FFFFFF);// the colour parameter in SetPixelgdi32::Windows.Win32.Foundation.COLORREFpixel=gdi32::Windows.Win32.PInvoke(context,x,y,white);
In practice, you might prefer to use a nicer, using statement, rather than repeating the alias throughout the document:
externaliasgdi32;usinggdi32::Windows.Win32;// Then you can reference the P/Invoke APIs like so:PInvoke.SetPixel();
Or, optionally, if you need access to P/Invoke APIs from multiple Win32 API sets but want to keep your codebase clean: