Click here to Skip to main content
15,511,981 members
Articles / Multimedia / DirectX
Posted 24 Jul 2016


8 bookmarked

Desktop Duplication API in Delphi

Rate me:
Please Sign up or sign in to vote.
4.05/5 (9 votes)
24 Jul 2016CPOL2 min read
Desktop Duplication API in Delphi


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.

    Image 1

  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.

    Image 2


  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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
AtelierWeb Software
Portugal Portugal
Jose Pascoa is the owner of AtelierWeb Software ( We produce security and network software and mixed utilities since 1999. The first program I published (in a BBS) was a MS-DOS utility, had the size of 21 KB and was done in Assembly Language. Nowadays, my low level languages are more likely to be "C", "C++" and "Delphi" rather than Assembly Language but I still like it. I have nothing against more fashionable languages like C# and technologies like WPF, actually I have played with them and published software with them.

Comments and Discussions

QuestionAny idea on how to serialize the data passed to displayManager? Pin
kikimorcho15-Jul-21 1:05
kikimorcho15-Jul-21 1:05 
AnswerRe: Any idea on how to serialize the data passed to displayManager? Pin
Jose A Pascoa15-Jul-21 2:52
Jose A Pascoa15-Jul-21 2:52 
AnswerRe: Any idea on how to serialize the data passed to displayManager? Pin
Jose A Pascoa20-Sep-21 3:19
Jose A Pascoa20-Sep-21 3:19 
QuestionHandle Pin
Member 1309558530-Mar-17 11:23
Member 1309558530-Mar-17 11:23 
AnswerRe: Handle Pin
Jose A Pascoa1-Apr-17 1:20
Jose A Pascoa1-Apr-17 1:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.