Skip to content

Instantly share code, notes, and snippets.

@Joshua-Ashton
Last active June 12, 2019 18:35
Show Gist options
  • Save Joshua-Ashton/2cb4f98763a7cbb798a008d526105d25 to your computer and use it in GitHub Desktop.
Save Joshua-Ashton/2cb4f98763a7cbb798a008d526105d25 to your computer and use it in GitHub Desktop.
// util_gdi.h
#pragma once
#include <d3d9.h>
namespace dxvk {
using NTSTATUS = LONG;
// Slightly modified definitions...
struct D3DKMT_CREATEDCFROMMEMORY {
void* pMemory;
D3DFORMAT Format;
UINT Width;
UINT Height;
UINT Pitch;
HDC hDeviceDc;
PALETTEENTRY* pColorTable;
HDC hDc;
HANDLE hBitmap;
};
struct D3DKMT_DESTROYDCFROMMEMORY {
HDC hDC = nullptr;
HANDLE hBitmap = nullptr;
};
typedef NTSTATUS(STDMETHODCALLTYPE* D3DKMTCreateDCFromMemoryType) (D3DKMT_CREATEDCFROMMEMORY*);
NTSTATUS D3DKMTCreateDCFromMemory(D3DKMT_CREATEDCFROMMEMORY* Arg1);
typedef NTSTATUS(STDMETHODCALLTYPE* D3DKMTDestroyDCFromMemoryType)(D3DKMT_DESTROYDCFROMMEMORY*);
NTSTATUS D3DKMTDestroyDCFromMemory(D3DKMT_DESTROYDCFROMMEMORY* Arg1);
}
// util_gdi.cpp
#include "util_gdi.h"
namespace dxvk {
HMODULE GetGDIModule() {
static HMODULE module = LoadLibraryA("gdi32.dll");
return module;
}
NTSTATUS D3DKMTCreateDCFromMemory(D3DKMT_CREATEDCFROMMEMORY* Arg1) {
static D3DKMTCreateDCFromMemoryType D3DKMTCreateDCFromMemoryFunc
= GetProcAddress(GetGDIModule(), "D3DKMTCreateDCFromMemory");
if (D3DKMTCreateDCFromMemoryFunc != nullptr)
return D3DKMTCreateDCFromMemoryFunc(Arg1);
Logger::warn("D3DKMTCreateDCFromMemory: Unable to query proc address.");
return -1;
}
NTSTATUS D3DKMTDestroyDCFromMemory(D3DKMT_DESTROYDCFROMMEMORY* Arg1) {
static D3DKMTDestroyDCFromMemoryType D3DKMTDestroyDCFromMemoryFunc
= (D3DKMTDestroyDCFromMemoryType)GetProcAddress(GetGDIModule(), "D3DKMTDestroyDCFromMemory");
if (D3DKMTDestroyDCFromMemoryFunc != nullptr)
return D3DKMTDestroyDCFromMemoryFunc(Arg1);
Logger::warn("D3DKMTDestroyDCFromMemory: Unable to query proc address.");
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment