Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __int64 __fastcall AcquireNextFrame(void* pThis, unsigned int timeout, void* pFrameInfo, IDXGIResource** ppDesktopResource)
- {
- __int64 ret = pAcquireNextFrame(pThis, timeout, pFrameInfo, ppDesktopResource);
- if (*ppDesktopResource == 0)
- {
- return ret;
- }
- ID3D11Texture2D *AcquiredDesktopImage;
- HRESULT res = (*ppDesktopResource)->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&AcquiredDesktopImage));
- if (res != S_OK)
- {
- char* nDbg = new char[255];
- sprintf(nDbg, "Query Interface Failed: %08X", res);
- MessageBoxA(NULL, nDbg, "ERROR", MB_OK);
- return ret;
- }
- ID3D11Device* pDevice;
- AcquiredDesktopImage->GetDevice(&pDevice);
- D3D11_TEXTURE2D_DESC desc;
- AcquiredDesktopImage->GetDesc(&desc);
- D3D11_SUBRESOURCE_DATA tbsd;
- int w = desc.Width;
- int h = desc.Height;
- int bpp = 4;
- int* buf = new int[w * h];
- // filling the image
- for (int i = 0; i < h; i++)
- for (int j = 0; j < w; j++)
- {
- if ((i & 32) == (j & 32))
- buf[i * w + j] = 0x00000000;
- else
- buf[i * w + j] = 0xffffffff;
- }
- // setting up D3D11_SUBRESOURCE_DATA
- tbsd.pSysMem = (void*)buf;
- tbsd.SysMemPitch = w * bpp;
- tbsd.SysMemSlicePitch = w * h * bpp; // Not needed since this is a 2d texture
- if (tex2d == NULL)
- {
- if (FAILED(pDevice->CreateTexture2D(&desc, &tbsd, &tex2d)))
- {
- char* nDbg = new char[255];
- sprintf(nDbg, "CreateTexture2D Failed %08X", GetLastError());
- MessageBoxA(NULL, nDbg, "ERROR", MB_OK);
- return ret;
- }
- }
- if (FAILED(tex2d->QueryInterface(__uuidof(IDXGIResource), reinterpret_cast<void**>(ppDesktopResource))))
- {
- char* nDbg = new char[255];
- sprintf(nDbg, "QueryInterface Failed: %08X", GetLastError());
- MessageBoxA(NULL, nDbg, "ERROR", MB_OK);
- tex2d->Release();
- AcquiredDesktopImage->Release();
- return ret;
- }
- else
- {
- AcquiredDesktopImage->Release();
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement