eugen15 / directx-present-hook

The project shows how to hook IDXGISwapChain::Present and capture window frames.
MIT License
29 stars 9 forks source link
directx directx-11 directx-12 directx11 directx12 dxgi hook

DirectX Present Hook

The project is an answer to this Stack Overflow question https://stackoverflow.com/questions/40538590/getting-dxgi-swapchain-by-hwnd. It shows how to hook IDXGISwapChain::Present (when it is used with DirectX 11/DirectX 12) to capture frames of a window which you do not control. For example, it can be used for some ActiveX controls which you integrate to your application. Probably, the project can be extended for more complicated tasks.

Source code

See the following classes:

The classes above are well commented. So, I hope that even if they do not solve your task directly, they may give you some ideas at least. The other classes are auxiliary or used to test the hooks by creating a "black box" window with a moving square.

Building

Visual Studio

Visual Studio 2019 v16.10 & v16.11 or later is required. Personally, I use Visual Studio 2022. The download link is here https://visualstudio.microsoft.com/vs/community/.

CMake

CMake is available as a part of Visual Studio 2022 installation. In my case it is located in the following folder: C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/. Install CMake separately https://cmake.org/ if your Visual Studio does not include it.

PolyHook 2

You need to compile this https://github.com/stevemk14ebr/PolyHook_2_0

DirectX Present Hook

The root folder contains example-prepare-x32.cmd and example-prepare-x64.cmd scripts.

Testing