Click here to Skip to main content
14,236,179 members

Desktop Duplication API in Delphi

Rate this:
4.05 (9 votes)
Please Sign up or sign in to vote.
4.05 (9 votes)
24 Jul 2016CPOL
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jose A Pascoa
AtelierWeb Software
Portugal Portugal
Jose Pascoa is the owner of AtelierWeb Software (http://www.atelierweb.com). 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

 
QuestionHandle Pin
Member 1309558530-Mar-17 10:23
memberMember 1309558530-Mar-17 10:23 
AnswerRe: Handle Pin
Jose A Pascoa1-Apr-17 0:20
memberJose A Pascoa1-Apr-17 0: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.

Article
Posted 24 Jul 2016

Stats

12.5K views
786 downloads
8 bookmarked