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.
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 grabed 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.