justinstenning / Direct3DHook

DirectX Capture and Overlays by using Direct3D API hooks
http://spazzarama.com/2011/03/14/c-screen-capture-and-overlays-for-direct3d-9-10-and-11-using-api-hooks
MIT License
582 stars 176 forks source link

DirectX surface size in windowed mode, and testing whether a directX surface is present. #4

Closed erikvullings closed 11 years ago

erikvullings commented 11 years ago

Hi,

I am currently using your great program to capture screenshots from DirectX devices like VLC or a game. As I am no DirectX expert, I wonder if you can help me with two issues:

Finally, as you are also the author of Easyhook, I wonder if it is possible to remove the hook injected via Easyhook? And is there a way to test whether an application is already hooked (or if I try to hook an app twice, will it only be hooked once)?

Thanks for any help you can give me! Erik

chenboo commented 11 years ago

1: use GetModuleHandle to know whether a application have already loaded "directx dll",if the function return value is not null,it mean this application doesn't use diretx. 2: u can use any hook method to hook (e.g. detours, mhook.),and hook shouldn't affect other existing hook .

justinstenning commented 11 years ago

Erik,

As chenboo said, use GetModuleHandle to determine if DX is loaded. This is in fact already happening in this project, it probably just needs a Thread.Sleep(100); at the end of the Run method to give the IPC time to deal with anything before exiting if no DX is loaded.

The Hooks can be removed by calling .Dispose() on the local hook instance. You cannot unload the .NET assemblies unless EasyHook is modified to create its own AppDomain. You can hook the same function multiple times, however its best to dispose of the hooks properly.

justinstenning commented 11 years ago

Regarding VLC - the size discrepancy is fairly unique to that application. I have had to modify the capture region in the past to deal with this exact issue with it.

chenboo commented 11 years ago

when the 'Present" is hooked,do u try to get backbuffer,and get the TEXTURE2D_DESC of the backbuffer to know the size?

justinstenning commented 11 years ago

When I retrieve the render target I then access the "Description" structure (which in this case I think will be a D3DSURFACE_DESC):

e.g.

using (Surface renderTargetTemp = device.GetRenderTarget(0)) { int width, height; width = renderTargetTemp.Description.Width; height = renderTargetTemp.Description.Height; }

The above is taken from DXHookD3D9.cs

chenboo commented 11 years ago

:+1: now i am off work,hava a nice day @spazzarama

chenboo commented 11 years ago

@spazzarama do u try to hook dwm.exe in win8? in win7,as we know,dwm.exe use dxgi to manage desktop.and when i hook the "Present" in dxgi.dll,i can capture the screen by get backbuffer. in win8,some guys say ,win8 cancle areo glass,means hook present can't get the backbuffer like i do in win7. after using windbg debug win8.i bp "" because i find this function is always called by dwm.exe.

chenboo commented 11 years ago

dxgi!CDXGISwapChain[::IDXGISwapChainDWM1]::Present1......

justinstenning commented 11 years ago

@chenboo - could you post a Gist or example here of the code you use to capture from DWM in Win7/8? Btw I've just uploaded a large changeset with major restructure of code and major changes (e.g. using SharpDX instead of SlimDX and so on).