HRESULT hr;
DDSURFACEDESC2 ddsd;
LPDIRECTDRAW lpdd1;
void *lpsurface;
LPDIRECTDRAW4 lpdd;
LPDIRECTDRAWSURFACE4 lpddsp;
if (DD_OK!=DirectDrawCreate(NULL,&lpdd1,NULL))return FALSE;
if(DD_OK!=(hr=lpdd1->QueryInterface(IID_IDirectDraw4,(void**)&lpdd)))return FALSE;
lpdd1->Release();
if(DD_OK!=lpdd->SetCooperativeLevel(hwnd,DDSCL_NORMAL))
{
if(FALSE==freeddraw())return FALSE;
}
if (lpsurface = malloc((size_t)640*360*3))
        ZeroMemory(lpsurface, (DWORD)640*360*3);
    else
        return DDERR_OUTOFMEMORY;

    // Initialize the surface description.
    // 初始化平面信息
    ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
    ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT));
    ddsd.dwSize = sizeof(ddsd);
    ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE|DDSD_PITCH | DDSD_PIXELFORMAT;
ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN;
    ddsd.dwWidth = 640;
    ddsd.dwHeight= 360;
    ddsd.lPitch  = (LONG)(3 * 640);
    ddsd.lpSurface = lpsurface;

    // Set up the pixel format for 24-bit RGB (8-8-8).
    // 为24-bit RGB(8-8-8)设置像素格式    ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
        ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB;
        ddsd.ddpfPixelFormat.dwRGBBitCount = (DWORD)(3*8);
        ddsd.ddpfPixelFormat.dwRBitMask    = 0x00FF0000;
        ddsd.ddpfPixelFormat.dwGBitMask    = 0x0000FF00;
        ddsd.ddpfPixelFormat.dwBBitMask    = 0x000000FF;
    

    // Create the surface
    // 创建平面
if(DD_OK!=(hr=lpdd->CreateSurface(&ddsd,&lpddsb,NULL)))
{
if(FALSE==freeddraw())return FALSE;
}
这个是我在网上的教程的,但是表面创建失败。hr是HRESULT:0x88760064,"DDERR_INVALIDCAPS", "One or more of the caps bits passed to the callback are incorrect."