Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Desktop Duplication API in Delphi

0.00/5 (No votes)
24 Jul 2016 2  
Desktop Duplication API in Delphi

Introduction

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.

Details

  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.

References

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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here