I am trying to hook Directx11 IDXGISwapChain.Present for getting screenshots using the Direct3DHook library and EasyHook. I guess the Direct3DHook is written for Single screenshots and I am trying to extend it to get a stream of screenshots. After the first few screenshots, the host application gets an exception at a random rendering stack.
I can isolate the error to the following code in the file DXHookD3D11.cs:
using (MemoryStream ms = new MemoryStream())
{
// This line crashes the main program, removing this makes the program not crash
res = Texture2D.ToStream(textureDest.Device.ImmediateContext, textureDest, ImageFileFormat.Bmp, ms).Code;
if (res != 0)
{
// this debugmessage never gets printed
this.DebugMessage("PresentHook: ERror in Tostream " + res.ToString());
}
.......
}