Jose's Blog

July 25, 2016

Desktop Duplication API in Delphi

Filed under: Uncategorized — jp2712 @ 8:57 am


One way some remote access applications speed up the screen capture on remote computers is by installing a Display Mirror Driver. Mirror Drivers exist since Windows 2000. However, for Windows 8 and above, Mirror Drivers will not install any more. Still, Microsoft decided to offer an alternative solution.
Such solution is called the Desktop Duplication API and is part of DirectX 11, more precisely the DXGI 1.2 update. Actually, the DirectX 11 API can fallback to versions 10 or 9, if the system does not support DirectX 11, but DXGI does not. Moreover, there will be no DXGI 1.2 for Windows 7 and Vista – you do need Windows 8 or later.

To get acquainted with the Desktop Duplication API, I went through the sample supplied by Microsoft. The fact is that I was not able to find much more samples elsewhere.
The sample supplied by Microsoft works on a single desktop, but that is just fine for its purpose.

DirectX is COM based, this means that you will have to master C or C++ to deal properly with it, right? Not exactly, Delphi is well tailored to deal with COM interfaces as well. I would say, that with Delphi, COM might even be easier, because it manages reference counting.

The Samples

I have produced 2 samples:
1) The first one mimics the Microsoft sample. I called it the Console Sample, although no console is actually there. It creates a window with the Windows API, launches one or more threads for the desktop duplication, then enters in an endless message loop to update the created window with the grabbed frames.

2) The second one is done more according to the Delphi way of doing things. Here a VCL Form is created and the grabbed frames update a TPanel component inside the Form. I choose a TPanel because it is TWinControl descendant, so has an HWND.



1) DirectX header files are from Reference 3, below. Great work (a lot of it, indeed!)
2) Pixel Shaders and Vertex Shaders are not directly compiled by the samples. Instead I inserted the precompiled results inside the PixelShader and VertexShader units.


  1. Desktop Duplication API
  2. DXGI desktop duplication sample
  3. DelphiDX12 Headers


SourceCode and Binaries



Create a free website or blog at