2

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.

glutz
  • 1,889
  • 7
  • 29
  • 44
  • It's a self-solving question. The 4 bytes initiates the E_INVALIDARG because the 64bit system that you are running can't understand the 32bit ddsd. – alexyorke Apr 07 '11 at 20:07
  • I'm not sure i understand. Do you suggest a solution? The 4 extra bytes im referring to is a surface ptr in the ddsd. – glutz Apr 07 '11 at 22:17
  • 1
    Interesting, I wouldn't have thought there was even an x64 version of DirectDraw, but I see here -- http://blogs.msdn.com/b/chuckw/archive/2010/06/16/wither-directdraw.aspx that it is supported. You may have just discovered a bug, what happens if you lie to it about the size of the structure (i.e. give it the 32 bit size)? And @alexy13 your response seems nonsensical, what does that even mean? – eodabash Apr 11 '11 at 21:34

2 Answers2

1

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.

cfh
  • 4,576
  • 1
  • 24
  • 34
1

solution:

#ifndef WIN64
#include <ddraw.h>
#else
#pragma pack(push, 8)
#include <ddraw.h>
#pragma pack(pop)
#endif
glutz
  • 1,889
  • 7
  • 29
  • 44