C++ Library with C exports to capture screen with Windows Desktop Duplication API
Original code from WindowsDesktopDuplicationSample!
This library is used by CSAuto to capture the screen of CS2
- Multi-monitor support
- Rotation handling
- C exports for easy interop with C# and other languages
- Windows 8 or later
- DXGI 1.2+ compatible GPU
- DirectX 11 support
- Open the solution in Visual Studio 2022
- Select your target platform (x64 or x86)
- Build the project (Release or Debug configuration)
- The compiled DLL will be in the
binfolder
C#
Example DXGIcapture.cs class in here
// Create new DXGICapture object
DXGICapture DXGIcapture = new DXGICapture();
// Initialize the capture
DXGIcapture.Init();
// Get pointer to the bitmap
IntPtr _handle = DXGIcapture.GetCapture();
// Check for invalid capture
if (_handle == IntPtr.Zero)
{
DXGIcapture.DeInit();
DXGIcapture.Init();
_handle = DXGIcapture.GetCapture();
}
using (Bitmap bitmap = Image.FromHbitmap(_handle))
{
// Do stuff with bitmap
}
// Deinitialize capture
DXGIcapture.DeInit();The C++ library is NOT thread-safe. All methods must be called from a single thread or externally synchronized. The C# wrapper provides thread-safety through locking.
MIT License - See LICENSE file for details
Copyright (c) 2025 MurkyYT