Created
August 14, 2020 11:46
-
-
Save realmonster/0af97e2d1e040182b7751558469f409e to your computer and use it in GitHub Desktop.
DirectDraw small test of API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <windows.h> | |
#include <ddraw.h> | |
char * GetErr(HRESULT r) | |
{ | |
switch(r) { | |
case DD_OK: return "DD_OK"; | |
case DDERR_ALREADYINITIALIZED: return "DDERR_ALREADYINITIALIZED"; | |
case DDERR_CANNOTATTACHSURFACE: return "DDERR_CANNOTATTACHSURFACE"; | |
case DDERR_CANNOTDETACHSURFACE: return "DDERR_CANNOTDETACHSURFACE"; | |
case DDERR_CURRENTLYNOTAVAIL: return "DDERR_CURRENTLYNOTAVAIL"; | |
case DDERR_EXCEPTION: return "DDERR_EXCEPTION"; | |
case DDERR_GENERIC: return "DDERR_GENERIC"; | |
case DDERR_HEIGHTALIGN: return "DDERR_HEIGHTALIGN"; | |
case DDERR_INCOMPATIBLEPRIMARY: return "DDERR_INCOMPATIBLEPRIMARY"; | |
case DDERR_INVALIDCAPS: return "DDERR_INVALIDCAPS"; | |
case DDERR_INVALIDCLIPLIST: return "DDERR_INVALIDCLIPLIST"; | |
case DDERR_INVALIDMODE: return "DDERR_INVALIDMODE"; | |
case DDERR_INVALIDOBJECT: return "DDERR_INVALIDOBJECT"; | |
case DDERR_INVALIDPARAMS: return "DDERR_INVALIDPARAMS"; | |
case DDERR_INVALIDPIXELFORMAT: return "DDERR_INVALIDPIXELFORMAT"; | |
case DDERR_INVALIDRECT: return "DDERR_INVALIDRECT"; | |
case DDERR_LOCKEDSURFACES: return "DDERR_LOCKEDSURFACES"; | |
case DDERR_NO3D: return "DDERR_NO3D"; | |
case DDERR_NOALPHAHW: return "DDERR_NOALPHAHW"; | |
case DDERR_NOSTEREOHARDWARE: return "DDERR_NOSTEREOHARDWARE"; | |
case DDERR_NOSURFACELEFT: return "DDERR_NOSURFACELEFT"; | |
case DDERR_NOCLIPLIST: return "DDERR_NOCLIPLIST"; | |
case DDERR_NOCOLORCONVHW: return "DDERR_NOCOLORCONVHW"; | |
case DDERR_NOCOOPERATIVELEVELSET: return "DDERR_NOCOOPERATIVELEVELSET"; | |
case DDERR_NOCOLORKEY: return "DDERR_NOCOLORKEY"; | |
case DDERR_NOCOLORKEYHW: return "DDERR_NOCOLORKEYHW"; | |
case DDERR_NODIRECTDRAWSUPPORT: return "DDERR_NODIRECTDRAWSUPPORT"; | |
case DDERR_NOEXCLUSIVEMODE: return "DDERR_NOEXCLUSIVEMODE"; | |
case DDERR_NOFLIPHW: return "DDERR_NOFLIPHW"; | |
case DDERR_NOGDI: return "DDERR_NOGDI"; | |
case DDERR_NOMIRRORHW: return "DDERR_NOMIRRORHW"; | |
case DDERR_NOTFOUND: return "DDERR_NOTFOUND"; | |
case DDERR_NOOVERLAYHW: return "DDERR_NOOVERLAYHW"; | |
case DDERR_OVERLAPPINGRECTS: return "DDERR_OVERLAPPINGRECTS"; | |
case DDERR_NORASTEROPHW: return "DDERR_NORASTEROPHW"; | |
case DDERR_NOROTATIONHW: return "DDERR_NOROTATIONHW"; | |
case DDERR_NOSTRETCHHW: return "DDERR_NOSTRETCHHW"; | |
case DDERR_NOT4BITCOLOR: return "DDERR_NOT4BITCOLOR"; | |
case DDERR_NOT4BITCOLORINDEX: return "DDERR_NOT4BITCOLORINDEX"; | |
case DDERR_NOT8BITCOLOR: return "DDERR_NOT8BITCOLOR"; | |
case DDERR_NOTEXTUREHW: return "DDERR_NOTEXTUREHW"; | |
case DDERR_NOVSYNCHW: return "DDERR_NOVSYNCHW"; | |
case DDERR_NOZBUFFERHW: return "DDERR_NOZBUFFERHW"; | |
case DDERR_NOZOVERLAYHW: return "DDERR_NOZOVERLAYHW"; | |
case DDERR_OUTOFCAPS: return "DDERR_OUTOFCAPS"; | |
case DDERR_OUTOFMEMORY: return "DDERR_OUTOFMEMORY"; | |
case DDERR_OUTOFVIDEOMEMORY: return "DDERR_OUTOFVIDEOMEMORY"; | |
case DDERR_OVERLAYCANTCLIP: return "DDERR_OVERLAYCANTCLIP"; | |
//case DDERR_OVERLAYCOLORKEYONLYONEA: return "DDERR_OVERLAYCOLORKEYONLYONEA"; | |
case DDERR_PALETTEBUSY: return "DDERR_PALETTEBUSY"; | |
case DDERR_COLORKEYNOTSET: return "DDERR_COLORKEYNOTSET"; | |
case DDERR_SURFACEALREADYATTACHED: return "DDERR_SURFACEALREADYATTACHED"; | |
case DDERR_SURFACEALREADYDEPENDENT: return "DDERR_SURFACEALREADYDEPENDENT"; | |
case DDERR_SURFACEBUSY: return "DDERR_SURFACEBUSY"; | |
case DDERR_CANTLOCKSURFACE: return "DDERR_CANTLOCKSURFACE"; | |
case DDERR_SURFACEISOBSCURED: return "DDERR_SURFACEISOBSCURED"; | |
case DDERR_SURFACELOST: return "DDERR_SURFACELOST"; | |
case DDERR_SURFACENOTATTACHED: return "DDERR_SURFACENOTATTACHED"; | |
case DDERR_TOOBIGHEIGHT: return "DDERR_TOOBIGHEIGHT"; | |
case DDERR_TOOBIGSIZE: return "DDERR_TOOBIGSIZE"; | |
case DDERR_TOOBIGWIDTH: return "DDERR_TOOBIGWIDTH"; | |
case DDERR_UNSUPPORTED: return "DDERR_UNSUPPORTED"; | |
case DDERR_UNSUPPORTEDFORMAT: return "DDERR_UNSUPPORTEDFORMAT"; | |
case DDERR_UNSUPPORTEDMASK: return "DDERR_UNSUPPORTEDMASK"; | |
case DDERR_INVALIDSTREAM: return "DDERR_INVALIDSTREAM"; | |
case DDERR_VERTICALBLANKINPROGRESS: return "DDERR_VERTICALBLANKINPROGRESS"; | |
case DDERR_WASSTILLDRAWING: return "DDERR_WASSTILLDRAWING"; | |
case DDERR_DDSCAPSCOMPLEXREQUIRED: return "DDERR_DDSCAPSCOMPLEXREQUIRED"; | |
case DDERR_XALIGN: return "DDERR_XALIGN"; | |
case DDERR_INVALIDDIRECTDRAWGUID: return "DDERR_INVALIDDIRECTDRAWGUID"; | |
//case DDERR_DIRECTDRAWALREADYCREATE: return "DDERR_DIRECTDRAWALREADYCREATE"; | |
case DDERR_NODIRECTDRAWHW: return "DDERR_NODIRECTDRAWHW"; | |
//case DDERR_PRIMARYSURFACEALREADYEX: return "DDERR_PRIMARYSURFACEALREADYEX"; | |
case DDERR_NOEMULATION: return "DDERR_NOEMULATION"; | |
case DDERR_REGIONTOOSMALL: return "DDERR_REGIONTOOSMALL"; | |
case DDERR_CLIPPERISUSINGHWND: return "DDERR_CLIPPERISUSINGHWND"; | |
case DDERR_NOCLIPPERATTACHED: return "DDERR_NOCLIPPERATTACHED"; | |
case DDERR_NOHWND: return "DDERR_NOHWND"; | |
case DDERR_HWNDSUBCLASSED: return "DDERR_HWNDSUBCLASSED"; | |
case DDERR_HWNDALREADYSET: return "DDERR_HWNDALREADYSET"; | |
case DDERR_NOPALETTEATTACHED: return "DDERR_NOPALETTEATTACHED"; | |
case DDERR_NOPALETTEHW: return "DDERR_NOPALETTEHW"; | |
case DDERR_BLTFASTCANTCLIP: return "DDERR_BLTFASTCANTCLIP"; | |
case DDERR_NOBLTHW: return "DDERR_NOBLTHW"; | |
case DDERR_NODDROPSHW: return "DDERR_NODDROPSHW"; | |
case DDERR_OVERLAYNOTVISIBLE: return "DDERR_OVERLAYNOTVISIBLE"; | |
case DDERR_NOOVERLAYDEST: return "DDERR_NOOVERLAYDEST"; | |
case DDERR_INVALIDPOSITION: return "DDERR_INVALIDPOSITION"; | |
case DDERR_NOTAOVERLAYSURFACE: return "DDERR_NOTAOVERLAYSURFACE"; | |
case DDERR_EXCLUSIVEMODEALREADYSET: return "DDERR_EXCLUSIVEMODEALREADYSET"; | |
case DDERR_NOTFLIPPABLE: return "DDERR_NOTFLIPPABLE"; | |
case DDERR_CANTDUPLICATE: return "DDERR_CANTDUPLICATE"; | |
case DDERR_NOTLOCKED: return "DDERR_NOTLOCKED"; | |
case DDERR_CANTCREATEDC: return "DDERR_CANTCREATEDC"; | |
case DDERR_NODC: return "DDERR_NODC"; | |
case DDERR_WRONGMODE: return "DDERR_WRONGMODE"; | |
case DDERR_IMPLICITLYCREATED: return "DDERR_IMPLICITLYCREATED"; | |
case DDERR_NOTPALETTIZED: return "DDERR_NOTPALETTIZED"; | |
case DDERR_UNSUPPORTEDMODE: return "DDERR_UNSUPPORTEDMODE"; | |
case DDERR_NOMIPMAPHW: return "DDERR_NOMIPMAPHW"; | |
case DDERR_INVALIDSURFACETYPE: return "DDERR_INVALIDSURFACETYPE"; | |
case DDERR_NOOPTIMIZEHW: return "DDERR_NOOPTIMIZEHW"; | |
case DDERR_NOTLOADED: return "DDERR_NOTLOADED"; | |
case DDERR_NOFOCUSWINDOW: return "DDERR_NOFOCUSWINDOW"; | |
case DDERR_NOTONMIPMAPSUBLEVEL: return "DDERR_NOTONMIPMAPSUBLEVEL"; | |
case DDERR_DCALREADYCREATED: return "DDERR_DCALREADYCREATED"; | |
case DDERR_NONONLOCALVIDMEM: return "DDERR_NONONLOCALVIDMEM"; | |
case DDERR_CANTPAGELOCK: return "DDERR_CANTPAGELOCK"; | |
case DDERR_CANTPAGEUNLOCK: return "DDERR_CANTPAGEUNLOCK"; | |
case DDERR_NOTPAGELOCKED: return "DDERR_NOTPAGELOCKED"; | |
case DDERR_MOREDATA: return "DDERR_MOREDATA"; | |
case DDERR_EXPIRED: return "DDERR_EXPIRED"; | |
case DDERR_TESTFINISHED: return "DDERR_TESTFINISHED"; | |
case DDERR_NEWMODE: return "DDERR_NEWMODE"; | |
case DDERR_D3DNOTINITIALIZED: return "DDERR_D3DNOTINITIALIZED"; | |
case DDERR_VIDEONOTACTIVE: return "DDERR_VIDEONOTACTIVE"; | |
case DDERR_NOMONITORINFORMATION: return "DDERR_NOMONITORINFORMATION"; | |
case DDERR_NODRIVERSUPPORT: return "DDERR_NODRIVERSUPPORT"; | |
case DDERR_DEVICEDOESNTOWNSURFACE: return "DDERR_DEVICEDOESNTOWNSURFACE"; | |
case DDERR_NOTINITIALIZED: return "DDERR_NOTINITIALIZED"; | |
default: return "UNKNOWN"; | |
} | |
} | |
void GarbageFill(void *mem, size_t size) | |
{ | |
for (int i = 0; i < size; ++i) | |
((char*)mem)[i] = i+5; | |
} | |
void HexDump(void *mem, size_t size) | |
{ | |
printf("=====\n"); | |
for (int i = 0; i < size; ++i) | |
{ | |
if (i % 16 == 0) | |
printf("%02X:", i); | |
printf(" %02X", ((unsigned char*)mem)[i]); | |
if (i + 1 < size && (i + 1) % 16 == 0) | |
printf("\n"); | |
} | |
printf("\n"); | |
fflush(stdout); | |
} | |
template <class T> | |
struct Verify | |
{ | |
union { | |
T val; | |
char data[sizeof(T)+48]; | |
}; | |
Verify(bool bad) | |
{ | |
GarbageFill(data, sizeof(data)); | |
if (!bad) | |
{ | |
val.dwSize = sizeof(T); | |
} | |
} | |
~Verify() | |
{ | |
char data1[sizeof(data)]; | |
GarbageFill(data1, sizeof(data1)); | |
bool bad = false; | |
for (int i = sizeof(T); i < sizeof(data); ++i) | |
{ | |
if (data1[i] != data[i]) | |
{ | |
bad = true; | |
break; | |
} | |
} | |
HexDump(&val, sizeof(val)); | |
if (bad) | |
{ | |
printf("Error: memory corruption\n=====Full Corrupted Dump"); | |
HexDump(data, sizeof(data)); | |
} | |
} | |
}; | |
LRESULT WINAPI WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | |
{ | |
return DefWindowProc(hwnd, uMsg, wParam, lParam); | |
} | |
HRESULT WINAPI enummodescallback1( | |
LPDDSURFACEDESC Arg1, | |
LPVOID Arg2 | |
) | |
{ | |
printf("Size: %d Mode: %dx%d %d\n", Arg1->dwSize, Arg1->dwWidth, Arg1->dwHeight, Arg1->ddpfPixelFormat.dwRGBBitCount); | |
if (Arg1->ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
HexDump(Arg1, sizeof(*Arg1)); | |
return DDENUMRET_OK; | |
} | |
HRESULT WINAPI enummodescallback2( | |
LPDDSURFACEDESC2 Arg1, | |
LPVOID Arg2 | |
) | |
{ | |
printf("Size: %d Mode: %dx%d %d\n", Arg1->dwSize, Arg1->dwWidth, Arg1->dwHeight, Arg1->ddpfPixelFormat.dwRGBBitCount); | |
if (Arg1->ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
HexDump(Arg1, sizeof(*Arg1)); | |
return DDENUMRET_OK; | |
} | |
int main() | |
{ | |
LPDIRECTDRAW dd1; | |
HRESULT res = DirectDrawCreate(NULL, &dd1, NULL); | |
printf("DirectDrawCreate: %s\n", GetErr(res)); | |
if (res != DD_OK) | |
return 1; | |
DDCAPS ddcaps; | |
int sizes[] = {5, sizeof(DDCAPS_DX1), sizeof(DDCAPS_DX3), sizeof(DDCAPS_DX5), sizeof(DDCAPS_DX6), sizeof(DDCAPS_DX7)}; | |
for (int i = 0; i < 6; ++i) | |
{ | |
GarbageFill(&ddcaps, sizeof(ddcaps)); | |
DDCAPS ddcaps1 = ddcaps; | |
ddcaps.dwSize = sizes[i]; | |
res = dd1->GetCaps((DDCAPS*)&ddcaps, NULL); | |
printf("dd1->GetCaps: %s\n", GetErr(res)); | |
if (res == DD_OK) | |
{ | |
printf("ddcaps.dwSize %d\n", ddcaps.dwSize); | |
} | |
if (memcmp((char*)&ddcaps+sizes[i], (char*)&ddcaps1+sizes[i], sizeof(DDCAPS)-sizes[i])) | |
{ | |
printf("Error: memory corruption\n=====Full Corrupted Dump"); | |
} | |
HexDump(&ddcaps, sizeof(ddcaps)); | |
} | |
LPDIRECTDRAW7 dd7; | |
res = dd1->QueryInterface(IID_IDirectDraw7, (LPVOID*)&dd7); | |
printf("dd1->QueryInterface(IID_IDirectDraw7) %s\n", GetErr(res)); | |
if (res == DD_OK) | |
{ | |
WNDCLASS wc; | |
res = dd7->SetCooperativeLevel(NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE); | |
printf("dd7->SetCooperativeLevel(NULL, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) %s\n", GetErr(res)); | |
ZeroMemory(&wc, sizeof(wc)); | |
wc.lpfnWndProc = WindowProc; | |
wc.cbWndExtra = 0; | |
wc.hInstance = GetModuleHandle(NULL); | |
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | |
wc.style = NULL; | |
wc.lpszClassName = "qwe"; | |
RegisterClass(&wc); | |
HWND hwnd = CreateWindowA("qwe", "qwe", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 800, 600, NULL, NULL, GetModuleHandle(NULL), NULL); | |
res = dd7->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE); | |
printf("dd7->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) %s\n", GetErr(res)); | |
// DirectDraw1 | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(true); | |
res = dd1->EnumDisplayModes(DDEDM_REFRESHRATES, &ddsdesc.val, NULL, enummodescallback1); | |
printf("dd1->EnumDisplayModes(DDEDM_REFRESHRATES, garbage size) %s\n", GetErr(res)); | |
} | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
res = dd1->EnumDisplayModes(DDEDM_REFRESHRATES, &ddsdesc.val, NULL, enummodescallback1); | |
printf("dd1->EnumDisplayModes(DDEDM_REFRESHRATES, correct size) %s\n", GetErr(res)); | |
} | |
// DirectDraw7 | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(true); | |
res = dd7->EnumDisplayModes(DDEDM_REFRESHRATES, &ddsdesc2.val, NULL, enummodescallback2); | |
printf("dd7->EnumDisplayModes(DDEDM_REFRESHRATES, garbage size) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
} | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
res = dd7->EnumDisplayModes(DDEDM_REFRESHRATES, &ddsdesc2.val, NULL, enummodescallback2); | |
printf("dd7->EnumDisplayModes(DDEDM_REFRESHRATES, correct size) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
} | |
res = dd7->SetDisplayMode(1024, 768, 16, 60, 0); | |
printf("dd7->SetDisplayMode(1024, 768, 16, 60, 0) %s\n", GetErr(res)); | |
if (res == DD_OK) | |
{ | |
LPDIRECTDRAWSURFACE7 surf7; | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
ddsdesc2.val.dwFlags = DDSD_CAPS; | |
ZeroMemory(&ddsdesc2.val.ddsCaps, sizeof(ddsdesc2.val.ddsCaps)); | |
ddsdesc2.val.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_VIDEOMEMORY; | |
res = dd7->CreateSurface(&ddsdesc2.val, &surf7, NULL); | |
printf("dd7->CreateSurface(DDSURFACEDESC2) %s\n", GetErr(res)); | |
} | |
if (res == DD_OK) | |
{ | |
// DirectDrawSurface7->GetSurfaceDesc DDSURFACEDESC2 Test | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
res = surf7->GetSurfaceDesc(&ddsdesc2.val); | |
printf("surf7->GetSurfaceDesc(DDSURFACEDESC2) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc2.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
// DirectDrawSurface7->GetSurfaceDesc DDSURFACEDESC Test | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
res = surf7->GetSurfaceDesc((LPDDSURFACEDESC2)&ddsdesc.val); | |
printf("surf7->GetSurfaceDesc(DDSURFACEDESC) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc.val.dwSize != sizeof(ddsdesc.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
// DirectDrawSurface7->Lock DDSURFACEDESC2 Test | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
res = surf7->Lock(NULL, &ddsdesc2.val, DDLOCK_WAIT, NULL); | |
printf("surf7->Lock(DDSURFACEDESC2) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc2.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
if (res == DD_OK) | |
{ | |
surf7->Unlock(NULL); | |
printf("surf7->Unlock() %s\n", GetErr(res)); | |
} | |
// DirectDrawSurface7->Lock DDSURFACEDESC Test | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
res = surf7->Lock(NULL, (LPDDSURFACEDESC2)&ddsdesc.val, DDLOCK_WAIT, NULL); | |
printf("surf7->Lock(DDSURFACEDESC) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc.val.dwSize != sizeof(ddsdesc.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
if (res == DD_OK) | |
{ | |
surf7->Unlock(NULL); | |
printf("surf7->Unlock() %s\n", GetErr(res)); | |
} | |
LPDIRECTDRAWSURFACE surf1 = NULL; | |
res = surf7->QueryInterface(IID_IDirectDrawSurface, (LPVOID*)&surf1); | |
printf("surf7->QueryInterface(IID_IDirectDrawSurface, &surf1) %s\n", GetErr(res)); | |
if (res = DD_OK) | |
{ | |
// DirectDrawSurface1->GetSurfaceDesc DDSURFACEDESC2 Test | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
res = surf1->GetSurfaceDesc((LPDDSURFACEDESC)&ddsdesc2.val); | |
printf("surf1->GetSurfaceDesc(DDSURFACEDESC2) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc2.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
// DirectDrawSurface1->GetSurfaceDesc DDSURFACEDESC Test | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
res = surf1->GetSurfaceDesc(&ddsdesc.val); | |
printf("surf1->GetSurfaceDesc(DDSURFACEDESC) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc.val.dwSize != sizeof(ddsdesc.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
// DirectDrawSurface1->Lock DDSURFACEDESC2 Test | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
res = surf1->Lock(NULL, (LPDDSURFACEDESC)&ddsdesc2.val, DDLOCK_WAIT, NULL); | |
printf("surf1->Lock(DDSURFACEDESC2) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc2.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
if (res == DD_OK) | |
{ | |
surf1->Unlock(NULL); | |
printf("surf1->Unlock() %s\n", GetErr(res)); | |
} | |
// DirectDrawSurface1->Lock DDSURFACEDESC Test | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
res = surf1->Lock(NULL, &ddsdesc.val, DDLOCK_WAIT, NULL); | |
printf("surf1->Lock(DDSURFACEDESC) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc.val.dwSize != sizeof(ddsdesc.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
if (res == DD_OK) | |
{ | |
surf1->Unlock(NULL); | |
printf("surf1->Unlock() %s\n", GetErr(res)); | |
} | |
} | |
DDPIXELFORMAT ddpf; // save pixel format for later use | |
// DirectDraw7->GetDisplayMode DDSURFACEDESC2 Test | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
res = dd7->GetDisplayMode(&ddsdesc2.val); | |
printf("dd7->GetDisplayMode(DDSURFACEDESC2) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc2.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
if (res == DD_OK) | |
{ | |
ddpf = ddsdesc2.val.ddpfPixelFormat; | |
} | |
} | |
// DirectDraw7->GetDisplayMode DDSURFACEDESC Test | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
res = dd7->GetDisplayMode((LPDDSURFACEDESC2)&ddsdesc.val); | |
printf("dd7->GetDisplayMode(DDSURFACEDESC) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc.val.dwSize != sizeof(ddsdesc.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
// DirectDraw1->GetDisplayMode DDSURFACEDESC2 Test | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
res = dd1->GetDisplayMode((LPDDSURFACEDESC)&ddsdesc2.val); | |
printf("dd1->GetDisplayMode(DDSURFACEDESC2) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc2.val.dwSize != sizeof(ddsdesc2.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc2.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
if (res == DD_OK) | |
{ | |
ddpf = ddsdesc2.val.ddpfPixelFormat; | |
} | |
} | |
// DirectDraw1->GetDisplayMode DDSURFACEDESC Test | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
res = dd1->GetDisplayMode(&ddsdesc.val); | |
printf("dd1->GetDisplayMode(DDSURFACEDESC) %s\n", GetErr(res)); | |
if (res == DD_OK && ddsdesc.val.dwSize != sizeof(ddsdesc.val)) | |
printf("Error: wrong dwSize\n"); | |
if (res == DD_OK && ddsdesc.val.ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)) | |
printf("Error: ddpfPixelFormat.dwSize != sizeof(DDPIXELFORMAT)\n"); | |
} | |
printf("DDPIXELFORMAT.dwSize = %d sizeof(DDPIXELFORMAT) = %d\n", ddpf.dwSize, sizeof(ddpf)); | |
// CreateSurface Test | |
// DirectDraw7 DDSURFACEDESC2 | |
{ | |
LPDIRECTDRAWSURFACE7 surf_unk; | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
ddsdesc2.val.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; | |
ZeroMemory(&ddsdesc2.val.ddsCaps, sizeof(ddsdesc2.val.ddsCaps)); | |
ddsdesc2.val.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; | |
ddsdesc2.val.dwWidth = 128; | |
ddsdesc2.val.dwHeight = 128; | |
ddsdesc2.val.ddpfPixelFormat = ddpf; | |
res = dd7->CreateSurface(&ddsdesc2.val, &surf_unk, NULL); | |
printf("dd7->CreateSurface(DDSURFACEDESC2) %s\n", GetErr(res)); | |
fflush(stdout); | |
} | |
if (res == DD_OK) | |
{ | |
LPDIRECTDRAWSURFACE7 surf7 = NULL; | |
LPDIRECTDRAWSURFACE surf1 = NULL; | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface7, (LPVOID*)&surf7); | |
if (res != DD_OK) | |
surf7 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface7) %s\n", GetErr(res)); | |
fflush(stdout); | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface, (LPVOID*)&surf1); | |
if (res != DD_OK) | |
surf1 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface) %s\n", GetErr(res)); | |
printf("surf_unk = %X surf7 = %X, surf1 = %X\n", (DWORD)surf_unk, (DWORD)surf7, (DWORD)surf1); | |
printf("surf_unk"); | |
if ((LPVOID)surf_unk == (LPVOID)surf7) | |
printf(" = IID_IDirectDrawSurface7"); | |
if ((LPVOID)surf_unk == (LPVOID)surf1) | |
printf(" = IID_IDirectDrawSurface"); | |
printf("\n"); | |
fflush(stdout); | |
if (surf7) | |
surf7->Release(); | |
if (surf1) | |
surf1->Release(); | |
surf_unk->Release(); | |
} | |
} | |
// CreateSurface Test | |
// DirectDraw7 DDSURFACEDESC | |
{ | |
LPDIRECTDRAWSURFACE7 surf_unk; | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
ddsdesc.val.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; | |
ZeroMemory(&ddsdesc.val.ddsCaps, sizeof(ddsdesc.val.ddsCaps)); | |
ddsdesc.val.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; | |
ddsdesc.val.dwWidth = 128; | |
ddsdesc.val.dwHeight = 128; | |
ddsdesc.val.ddpfPixelFormat = ddpf; | |
res = dd7->CreateSurface((LPDDSURFACEDESC2)&ddsdesc.val, &surf_unk, NULL); | |
printf("dd7->CreateSurface(DDSURFACEDESC) %s\n", GetErr(res)); | |
fflush(stdout); | |
} | |
if (res == DD_OK) | |
{ | |
LPDIRECTDRAWSURFACE7 surf7 = NULL; | |
LPDIRECTDRAWSURFACE surf1 = NULL; | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface7, (LPVOID*)&surf7); | |
if (res != DD_OK) | |
surf7 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface7) %s\n", GetErr(res)); | |
fflush(stdout); | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface, (LPVOID*)&surf1); | |
if (res != DD_OK) | |
surf1 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface) %s\n", GetErr(res)); | |
printf("surf_unk = %X surf7 = %X, surf1 = %X\n", (DWORD)surf_unk, (DWORD)surf7, (DWORD)surf1); | |
printf("surf_unk"); | |
if ((LPVOID)surf_unk == (LPVOID)surf7) | |
printf(" = IID_IDirectDrawSurface7"); | |
if ((LPVOID)surf_unk == (LPVOID)surf1) | |
printf(" = IID_IDirectDrawSurface"); | |
printf("\n"); | |
fflush(stdout); | |
if (surf7) | |
surf7->Release(); | |
if (surf1) | |
surf1->Release(); | |
surf_unk->Release(); | |
} | |
} | |
// CreateSurface Test | |
// DirectDraw1 DDSURFACEDESC2 | |
{ | |
LPDIRECTDRAWSURFACE surf_unk; | |
{ | |
Verify<DDSURFACEDESC2> ddsdesc2(false); | |
ddsdesc2.val.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; | |
ZeroMemory(&ddsdesc2.val.ddsCaps, sizeof(ddsdesc2.val.ddsCaps)); | |
ddsdesc2.val.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; | |
ddsdesc2.val.dwWidth = 128; | |
ddsdesc2.val.dwHeight = 128; | |
ddsdesc2.val.ddpfPixelFormat = ddpf; | |
res = dd1->CreateSurface((LPDDSURFACEDESC)&ddsdesc2.val, &surf_unk, NULL); | |
printf("dd1->CreateSurface(DDSURFACEDESC2) %s\n", GetErr(res)); | |
fflush(stdout); | |
} | |
if (res == DD_OK) | |
{ | |
LPDIRECTDRAWSURFACE7 surf7 = NULL; | |
LPDIRECTDRAWSURFACE surf1 = NULL; | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface7, (LPVOID*)&surf7); | |
if (res != DD_OK) | |
surf7 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface7) %s\n", GetErr(res)); | |
fflush(stdout); | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface, (LPVOID*)&surf1); | |
if (res != DD_OK) | |
surf1 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface) %s\n", GetErr(res)); | |
printf("surf_unk = %X surf7 = %X, surf1 = %X\n", (DWORD)surf_unk, (DWORD)surf7, (DWORD)surf1); | |
printf("surf_unk"); | |
if ((LPVOID)surf_unk == (LPVOID)surf7) | |
printf(" = IID_IDirectDrawSurface7"); | |
if ((LPVOID)surf_unk == (LPVOID)surf1) | |
printf(" = IID_IDirectDrawSurface"); | |
printf("\n"); | |
fflush(stdout); | |
if (surf7) | |
surf7->Release(); | |
if (surf1) | |
surf1->Release(); | |
surf_unk->Release(); | |
} | |
} | |
// CreateSurface Test | |
// DirectDraw1 DDSURFACEDESC | |
{ | |
LPDIRECTDRAWSURFACE surf_unk; | |
{ | |
Verify<DDSURFACEDESC> ddsdesc(false); | |
ddsdesc.val.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; | |
ZeroMemory(&ddsdesc.val.ddsCaps, sizeof(ddsdesc.val.ddsCaps)); | |
ddsdesc.val.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; | |
ddsdesc.val.dwWidth = 128; | |
ddsdesc.val.dwHeight = 128; | |
ddsdesc.val.ddpfPixelFormat = ddpf; | |
res = dd1->CreateSurface(&ddsdesc.val, &surf_unk, NULL); | |
printf("dd1->CreateSurface(DDSURFACEDESC) %s\n", GetErr(res)); | |
fflush(stdout); | |
} | |
if (res == DD_OK) | |
{ | |
LPDIRECTDRAWSURFACE7 surf7 = NULL; | |
LPDIRECTDRAWSURFACE surf1 = NULL; | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface7, (LPVOID*)&surf7); | |
if (res != DD_OK) | |
surf7 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface7) %s\n", GetErr(res)); | |
fflush(stdout); | |
res = surf_unk->QueryInterface(IID_IDirectDrawSurface, (LPVOID*)&surf1); | |
if (res != DD_OK) | |
surf1 = NULL; | |
printf("surf_unk->QueryInterface(IID_IDirectDrawSurface) %s\n", GetErr(res)); | |
printf("surf_unk = %X surf7 = %X, surf1 = %X\n", (DWORD)surf_unk, (DWORD)surf7, (DWORD)surf1); | |
printf("surf_unk"); | |
if ((LPVOID)surf_unk == (LPVOID)surf7) | |
printf(" = IID_IDirectDrawSurface7"); | |
if ((LPVOID)surf_unk == (LPVOID)surf1) | |
printf(" = IID_IDirectDrawSurface"); | |
printf("\n"); | |
fflush(stdout); | |
if (surf7) | |
surf7->Release(); | |
if (surf1) | |
surf1->Release(); | |
surf_unk->Release(); | |
} | |
} | |
if (surf1) | |
surf1->Release(); | |
surf7->Release(); | |
} | |
} | |
dd7->Release(); | |
DestroyWindow(hwnd); | |
} | |
dd1->Release(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment