CreateSurface in DirectDraw returns E_INVALIDARG on x64

1.3k Views Asked by At

In the following code, hRet gets set to E_INVALIDARG when built for x64.

The same code always works ok in 32 bit. The only clear difference in input is the sizeof ddsd, which is 4 bytes larger in 64 bit mode, because of a pointer size.

HRESULT hRet;
DDSURFACEDESC2 ddsd;
LPDIRECTDRAWSURFACE4 pTempDDrawSurface = NULL;

ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps |= DDSCAPS_PRIMARYSURFACE;

// Create primary surface
hRet = m_pRootDDrawObj->CreateSurface(&ddsd, &pTempDDrawSurface, NULL);
if (hRet != DD_OK)
    return -3;  //gets here with E_INVALIDARG, but GetLastError() is 0.

(OS is win7). Thanks for any advice.

2

There are 2 best solutions below

0
On

This is an old question, but I just ran into the same problem while porting some legacy code. The first thing here is that CreateSurface() expects the `dwSize´ field to be 0x88, while by default MSVC packs it into 0x80 bytes.

Applying the pack fix by glutz above does correct that issue, however then the CreateSurface() call returns E_NOINTERFACE (0x80004002). So far I can only guess that DirectDraw surfaces are simply not supported on x64.

0
On

solution:

#ifndef WIN64
#include <ddraw.h>
#else
#pragma pack(push, 8)
#include <ddraw.h>
#pragma pack(pop)
#endif