   Direct Draw initialization
  I've been using SDL, but wanted to check out DDraw. Below is the code I use, but for some reason it fails when creating the primary surface. What am I doing wrong? #include <windows.h>#include <ddraw.h>#ifndef WIN32_LEAN_AND_MEAN#define WIN32_LEAN_AND_MEAN#endifBOOL bActive;LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {switch(message) {case WM_ACTIVATEAPP:bActive = wParam;break;case WM_SETCURSOR:SetCursor(NULL);return TRUE;case WM_CREATE:break;case WM_KEYDOWN:switch(wParam) {case VK_ESCAPE:PostMessage(hWnd, WM_CLOSE, 0, 0);break;}break;case WM_DESTROY:PostQuitMessage(1);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0;}int STDCALL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {TCHAR szWindowClass[] = "Test";HWND hWnd;MSG msg;WNDCLASSEX wc;wc.cbSize= sizeof(WNDCLASSEX);wc.style= CS_HREDRAW | CS_VREDRAW;wc.lpfnWndProc= WndProc;wc.cbClsExtra= 0;wc.cbWndExtra= 0;wc.hInstance= hInstance;wc.hIcon= LoadIcon(hInstance, IDI_APPLICATION);wc.hIconSm= LoadIcon (hInstance, IDI_APPLICATION);wc.hCursor= LoadCursor(NULL, IDC_ARROW);wc.hbrBackground= (HBRUSH)GetStockObject(BLACK_BRUSH);wc.lpszMenuName= szWindowClass;wc.lpszClassName= szWindowClass;RegisterClassEx(&wc);hWnd = CreateWindow(szWindowClass,szWindowClass,WS_POPUP,0,0,1,1,NULL,NULL,hInstance,NULL);if(!hWnd) return FALSE;ShowWindow(hWnd, nCmdShow);UpdateWindow(hWnd);LPDIRECTDRAW7 lpDD = NULL;LPDIRECTDRAWSURFACE7 lpDDSPrimary = NULL;LPDIRECTDRAWSURFACE7 lpDDSBack = NULL;DDSURFACEDESC2 ddsd;DDSCAPS2 ddscaps;if(FAILED(DirectDrawCreateEx(NULL, (LPVOID *)&lpDD, IID_IDirectDraw7, NULL)))return FALSE;if(FAILED(lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT)))return FALSE;if (FAILED(lpDD->SetDisplayMode(640, 480, 16, 0, 0)))return FALSE;ZeroMemory(&ddsd, sizeof(ddsd));ddsd.dwSize = sizeof(ddsd);ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;ddsd.dwBackBufferCount = 1;if(FAILED(lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL)))return FALSE; // it fails here    ZeroMemory(&ddscaps, sizeof(ddscaps));ddscaps.dwCaps = DDSCAPS_BACKBUFFER; if(FAILED(lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack)))return FALSE;while(1) {if(PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {if(!GetMessage(&msg, NULL, 0, 0)) {return msg.wParam;}TranslateMessage(&msg); DispatchMessage(&msg);}else if(bActive) {lpDDSPrimary->Flip(NULL, 0); }else {WaitMessage();}}return msg.wParam;}[edited by - robinei on August 2, 2003 3:25:23 PM]
  Is it because all your dx objects are static? ;  I''ve absolutely no expirience with dx. What do you mean? ;quote:Original post by RhoneRanger  Is it because all your dx objects are static?   I have exp but still don''t understand your answer.   .lick;  Hmm it works now. I really don''t know what fixed it. I just tinkered with the code some, based on examples I found. 