#include <ddraw.h>
#pragma comment(lib, "dxguid.lib")
typedef HRESULT (WINAPI* T_GetCaps)(LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps, DWORD dwUnknown);
PDWORD g_pFuncGetCaps = NULL;
T_GetCaps g_FuncGetCaps = NULL;
HRESULT WINAPI My_GetCaps(LPDDCAPS lpDDDriverCaps, LPDDCAPS lpDDHELCaps, DWORD dwUnknown)
{
HRESULT hResult = g_FuncGetCaps(lpDDDriverCaps, lpDDHELCaps, NULL);
if (S_OK == hResult) {
lpDDHELCaps->dwVidMemTotal = 1000;
}
return hResult;
}
void vmem()
{
LPDIRECTDRAW2 lpdd = NULL;
::CoInitialize(NULL);
HRESULT ddrval = ::CoCreateInstance(CLSID_DirectDraw, NULL, CLSCTX_ALL, IID_IDirectDraw2, (void**)&lpdd);
if(!FAILED(ddrval)) {
ddrval = IDirectDraw2_Initialize(lpdd, NULL);
}
g_pFuncGetCaps = (PDWORD)(*(PDWORD)lpdd + 0x2C);
g_FuncGetCaps = (T_GetCaps)*g_pFuncGetCaps;
*g_pFuncGetCaps = (DWORD)My_GetCaps;
DDCAPS ddcaps;
ddcaps.dwSize = sizeof DDCAPS;
lpdd->GetCaps(&ddcaps, NULL);
lpdd->Release();
printf("display memory is %d ", ddcaps.dwVidMemTotal);
printf("display memory free is %d ", ddcaps.dwVidMemFree);
::CoUninitialize();
}
int _tmain(int argc, _TCHAR* argv[])
{
vmem();
getchar();
return 0;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!