LIBRARYINJECTORSHARED_EXPORT HRESULT PASCAL DllGetClassObject(REFCLSID objGuid, REFIID factoryGuid, void **factoryHandle) { register HRESULT hr; #ifdef DEBUG WCHAR guid[GUID_BUFFER_SIZE]; StringFromGUID2(objGuid, guid, _countof(guid)); reportLog(EVENTLOG_INFORMATION_TYPE, L"class guid %s",guid); StringFromGUID2(factoryGuid, guid, _countof(guid)); reportLog(EVENTLOG_INFORMATION_TYPE, L"factory guid %s", guid); #endif if (IsEqualCLSID(objGuid, &CLSID_ILibraryInjector)) { IClassFactory * classFactory = allocClassFactory(); if (classFactory) { classFactory->lpVtbl->AddRef(classFactory); // Fill in the caller's handle with a pointer to our IClassFactory object. // We'll let our IClassFactory's QueryInterface do that, because it also // checks the IClassFactory GUID and does other book-keeping hr = classFactory->lpVtbl->QueryInterface(classFactory, factoryGuid, factoryHandle); classFactory->lpVtbl->Release(classFactory); } else { hr = E_OUTOFMEMORY; } } else { #ifdef DEBUG WCHAR supportedGuid[GUID_BUFFER_SIZE], requestedGuid[GUID_BUFFER_SIZE]; StringFromGUID2(&CLSID_ILibraryInjector, supportedGuid, _countof(supportedGuid)); StringFromGUID2(objGuid, requestedGuid, _countof(requestedGuid)); reportLog(EVENTLOG_ERROR_TYPE, L"class guid is not matched. supported guid %s, requested guid %s", supportedGuid, requestedGuid); #endif // We don't understand this GUID. It's obviously not for our DLL. // Let the caller know this by clearing his handle and returning // CLASS_E_CLASSNOTAVAILABLE *factoryHandle = 0; hr = CLASS_E_CLASSNOTAVAILABLE; } return (hr); }
void D3D10Grab(ID3D10Texture2D* pBackBuffer) { D3D10_TEXTURE2D_DESC tex_desc; pBackBuffer->GetDesc(&tex_desc); ID3D10Device *pDev; pBackBuffer->GetDevice(&pDev); ID3D10Texture2D * pTexture; D3D10_MAPPED_TEXTURE2D mappedTexture; tex_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; tex_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; tex_desc.ArraySize = 1; tex_desc.MipLevels = 1; tex_desc.BindFlags = 0; tex_desc.SampleDesc.Count = 1; tex_desc.SampleDesc.Quality = 0; tex_desc.Usage = D3D10_USAGE_STAGING; tex_desc.MiscFlags = 0; HRESULT hr = pDev->CreateTexture2D(&tex_desc, NULL, &pTexture); #ifdef DEBUG reportLog(EVENTLOG_INFORMATION_TYPE, L"pDev->CreateTexture2D 0x%x", hr); #endif pDev->CopyResource(pTexture, pBackBuffer); D3D10_BOX box = {0, 0, tex_desc.Width, tex_desc.Height, 0, 1}; pDev->CopySubresourceRegion(pTexture, 0, 0, 0, 0, pBackBuffer, 0, &box); DxgiFrameGrabber *dxgiFrameGrabber = DxgiFrameGrabber::getInstance(); IPCContext *ipcContext = dxgiFrameGrabber->m_ipcContext; Logger *logger = dxgiFrameGrabber->m_logger; if (S_OK != (hr = pTexture->Map(D3D10CalcSubresource(0, 0, 1), D3D10_MAP_READ, 0, &mappedTexture))) { logger->reportLogError(L"d3d10 couldn't map texture, hresult = 0x%x", hr); goto end; } ipcContext->m_memDesc.width = tex_desc.Width; ipcContext->m_memDesc.height = tex_desc.Height; ipcContext->m_memDesc.rowPitch = mappedTexture.RowPitch; ipcContext->m_memDesc.format = BufferFormatAbgr; ipcContext->m_memDesc.frameId++; // reportLog(EVENTLOG_INFORMATION_TYPE, L"d3d10 texture description. width: %u, height: %u, pitch: %u", tex_desc.Width, tex_desc.Height, mappedTexture.RowPitch); DWORD errorcode; if (WAIT_OBJECT_0 == (errorcode = WaitForSingleObject(ipcContext->m_hMutex, 0))) { // __asm__("int $3"); // reportLog(EVENTLOG_INFORMATION_TYPE, L"d3d10 writing description to mem mapped file"); memcpy(ipcContext->m_pMemMap, &ipcContext->m_memDesc, sizeof (ipcContext->m_memDesc)); // reportLog(EVENTLOG_INFORMATION_TYPE, L"d3d10 writing data to mem mapped file"); PVOID pMemDataMap = incPtr(ipcContext->m_pMemMap, sizeof (ipcContext->m_memDesc)); if (mappedTexture.RowPitch == tex_desc.Width * 4) { memcpy(pMemDataMap, mappedTexture.pData, tex_desc.Width * tex_desc.Height * 4); } else { UINT cleanOffset = 0, pitchOffset = 0, i = 0; while (i < tex_desc.Height) { memcpy(incPtr(pMemDataMap, cleanOffset), incPtr(mappedTexture.pData, pitchOffset), tex_desc.Width * 4); cleanOffset += tex_desc.Width * 4; pitchOffset += mappedTexture.RowPitch; i++; } } ReleaseMutex(ipcContext->m_hMutex); SetEvent(ipcContext->m_hFrameGrabbedEvent); } else { logger->reportLogError(L"d3d10 couldn't wait mutex. errocode = 0x%x", errorcode); } pTexture->Unmap(D3D10CalcSubresource(0, 0, 1)); end: pTexture->Release(); pDev->Release(); }