0 Replies - 893 Views - Last Post: 23 November 2013 - 04:43 AM Rate Topic: -----

#1 Gabarel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 39
  • Joined: 19-August 13

The Hooking, the IDXGISwapChainDWM1 Class and other friends!

Posted 23 November 2013 - 04:43 AM

Hi everyone, I'm trying to hook the method Present1() member of IDXGISwapChainDWM1 Class which is not documented any where at all. I'm wondering if anyone of you would have some information about this "misterious" :) class.

Here my function BeforePresent1() that I call before evoke Present1() in another file:
//
//Called by detour IDXGISwapChainDWM1::Present1()
//

void BeforePresent1(IDXGISwapChainDWM1 *chain, UINT SyncInterval, UINT Flags,
                        Int mode)
{
  BOOL fullscreen;
  IDXGIOutput *target;
  IDXGISwapChainDWM1 * dwm1chain;
  HRESULT result;

  result = dwm1chain -> GetFullscreenState(&fullscreen, &target);

  if (result != S_OK)
  {
    #ifdef ERROR
    Log() << "BeforePresent: ERROR! Failed to retrieve fullscreen state "
          << "with result " << Htk(result) << ".\n";
    #endif
  }
  else
  {
    #ifdef TEST
    Log() << "BeforePresent: Fullscreen state is "
          << Itk(fullscreen) << ".\n";
    #endif
  }

  #ifdef TEST
  Log() << "BeforePresent: Mode is "
        << Stk(GetModeName(mode));
  #endif

  #ifdef TEST
  Log() << "BeforePresent1: Capturing Dwm7.\n";
  #endif
  ID3D10Texture2D *texture = NULL;
  ID3D10Texture2D *capture = NULL;
  ID3D10Device *device = NULL;

  ImageFormat format;

  unsigned Long width;
  unsigned Long height;

  Int multisample;

  result = dwm1chain -> GetBuffer(0, IID_ID3D10Texture2D,
                                         (void**) &texture);
  if (result != S_OK)
  {
    #ifdef ERROR
    Log() << "BeforePresent1: ERROR! Get buffer failed with result "
          << Htk(result) << ".\n";
    #endif

    goto D3D10PresentError;
  }

  D3D10_TEXTURE2D_DESC description;

  texture -> GetDesc(&description);

  #ifdef DEBUG

  Log() << "BeforePresent1 : Got texture description.\n";

  Log() << "Width:            " << Itk(description.Width) << ".\n";
  Log() << "Height:           " << Itk(description.Height) << ".\n";
  Log() << "MipLevels:        " << Itk(description.MipLevels) << ".\n";
  Log() << "ArraySize:        " << Itk(description.ArraySize) << ".\n";
  Log() << "Format:           " << Itk(description.Format) << ".\n";
  Log() << "Sample count:     " << Itk(description.SampleDesc.Count) << ".\n";
  Log() << "Sample quality:   " << Itk(description.SampleDesc.Quality) << ".\n";
  Log() << "Usage:            " << Itk(description.Usage) << ".\n";
  Log() << "BindFlags:        " << Itk(description.BindFlags) << ".\n";
  Log() << "CPUAccessFlags:   " << Itk(description.CPUAccessFlags) << ".\n";
  Log() << "MiscFlags:        " << Itk(description.MiscFlags) << ".\n";
  #endif

  format = TranslateDXGIFormat(description.Format);

  multisample = (description.SampleDesc.Count > 1);

  if (format == 0)
  {
    #ifdef ERROR
    Log() << "BeforePresent: Format unsupported.\n";
    #endif

    goto D3D10PresentError;
  }

    description.MipLevels = 1;
    description.ArraySize = 1;
    description.SampleDesc.Count = 1;
    description.SampleDesc.Quality = 0;
    description.Usage = D3D10_USAGE_STAGING;
    description.BindFlags = 0;
    description.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
    description.MiscFlags = 0;

    texture -> GetDevice(&device);

    result = device -> CreateTexture2D(&description, 0, &capture);

  if (result != S_OK)
  {
    #ifdef ERROR
    Log() << "BeforePresent1: ERROR! Create texture failed with result "
          << Htk(result) << ".\n";
    #endif

    goto D3D10PresentError;

    return;
  }

  if (multisample != 0)
  {
    ID3D10Texture2D *resolved = NULL;

    description.Usage = D3D10_USAGE_DEFAULT;
    description.CPUAccessFlags = 0;

    result = device -> CreateTexture2D(&description, 0, &resolved);

    if (result != S_OK)
    {
      #ifdef ERROR
      Log() << "BeforePresent1: ERROR: Failed creating resolved texture "
            << "with result " << Htk(result) << ".\n";
      #endif

      goto D3D10PresentMultiSampleError;
    }

    device -> ResolveSubresource(resolved, 0, texture, 0, description.Format);

    texture -> Release();

    texture = resolved;

    resolved = NULL;

    D3D10PresentMultiSampleError:

    if (resolved != NULL)
   {
     resolved -> Release();
   }
  }

  device -> CopySubresourceRegion((ID3D10Resource *) capture, 0, 0, 0, 0,
                                      (ID3D10Resource *) texture, 0, NULL);

  D3D10_MAPPED_TEXTURE2D map;

  result = capture -> Map(0, D3D10_MAP_READ, 0, &map);
  if (result != S_OK)
  {
    #ifdef ERROR
    Log() << "BeforePresent1: ERROR! Map failed with resutl "
          << Htk(result) << ".\n";
    #endif

    goto D3D10PresentError;
  }

  width = description.Width;
  height = description.Height;

  #ifdef DUMP_BACKBUFFER

  if (fullscreen != 0)
  {
    SaveBitmap(imagedir, width, height, (Char *) map.pData, map.RowPitch);
  }

  #endif

  WriteToSharedBuffer(width, height, (Char *) map.pData, map.RowPitch,
                          description.Format, fullscreen);

  capture -> Unmap(0);

  D3D10PresentError :

  if (device != NULL)
  {
    device -> Release();
  }

  if (texture != NULL)
  {
    texture -> Release();
  }

  if (capture != NULL)
  {
    capture -> Release();
  }
}



and here is what I snatched using a disassembler

struct DECLSPEC_UUID("73A36C8F-0228-7FC0-0000-000100000000")
IDXGISwapChainDWM1: public IDXGIDeviceSubObject
{
  virtual HRESULT STDMETHODCALLTYPE QueryInterface(_GUID const &,void * *) = 0;
  virtual ULONG   STDMETHODCALLTYPE AddRef(void) = 0;
  virtual HRESULT STDMETHODCALLTYPE Relese(void) = 0;
  virtual HRESULT STDMETHODCALLTYPE SetPrivateData(_GUID const &,UINT,void const *) = 0;
  virtual HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(_GUID const &,IUnknown const *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetPrivateData(_GUID const &,UINT *,void *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetParent(_GUID const &,void * *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetDevice(_GUID const &,void * *) = 0;
  virtual HRESULT STDMETHODCALLTYPE Present(UINT,UINT) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetBuffer(UINT,_GUID const &,void * *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetDesc(DXGI_SWAP_CHAIN_DESC *) = 0;
  virtual HRESULT STDMETHODCALLTYPE ResizeBuffer(UINT,UINT,UINT,DXGI_FORMAT,UINT) = 0;
  virtual HRESULT STDMETHODCALLTYPE ResizeTarget(DXGI_MODE_DESC const *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetContainigOutput(IDXGIOutput * *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetframeStatistic(DXGI_FRAME_STATISTICS *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetLastPresentCount(UINT *) = 0;
  virtual HRESULT STDMETHODCALLTYPE Present1(UINT,UINT,UINT,tagRECT const *,UINT, RECT const *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetLogicalSurfaceHandle(unsigned __int64 *) = 0;
  virtual HRESULT STDMETHODCALLTYPE CheckDirectFlipSupport(UINT,IDXGIResource *,int *) = 0;
  virtual HRESULT STDMETHODCALLTYPE Present2(UINT, UINT,UINT,tagRECT const *, UINT, RECT const *,IDXGIResource *) = 0;
  virtual HRESULT STDMETHODCALLTYPE GetCompositionSurface(void * *) = 0;
};



Now, my compiler issued this error:

Present.cpp: In function ‘void BeforePresent1(IDXGISwapChainDWM1*, UINT, UINT, int)’:
Present.cpp:47:25: error: ‘struct IDXGISwapChainDWM1’ has no member named ‘GetFullscreenState’

The reason is clear, but how could I some document on this Class.

Thanks at all.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1