I am new at using directX and am clueless as to why my GetAttachedSurface returns an error. This program works just fine with only one surface. I have included my WinMain function.
Code:
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
DDSURFACEDESC2 ddsd;
HRESULT hRet;
MSG msg;
HWND hWnd;
WNDCLASS wc;
LONGLONG cur_time;
DWORD time_count;
LONGLONG perf_cnt;
bool perf_flag=false;
LONGLONG next_time=0;
LONGLONG last_time=0;
double time_elapsed;
double time_scale;
wc.style =CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc =(WNDPROC)WindowProc;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hInstance;
wc.hIcon =LoadIcon(hInstance,"Rouslan");
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName =MAKEINTRESOURCE(IDR_MENU1);
wc.lpszClassName="Rouslan";
if(!RegisterClass(&wc))return false;
if(QueryPerformanceFrequency((LARGE_INTEGER*)&perf_cnt))
{
perf_flag=true;
time_count=perf_cnt/30;
QueryPerformanceCounter((LARGE_INTEGER*)&next_time);
time_scale=1.0/perf_cnt;
}else{
next_time=timeGetTime();
time_scale=0.001;
time_count=33;
}
last_time=next_time;
hInst=hInstance;
hWnd = CreateWindow(lpszAppName,lpszTitle,WS_POPUP,0,0,
GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hInstance,NULL);
if(!hWnd)return false;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
hRet=DirectDrawCreateEx(NULL,(LPVOID*)&lpDD,IID_IDirectDraw7,NULL);
if(hRet != DD_OK)return false;
hRet = lpDD->SetCooperativeLevel(hWnd,DDSCL_FULLSCREEN|DDSCL_EXCLUSIVE);
if(hRet != DD_OK)return false;
hRet = lpDD->SetDisplayMode(640,480,16,0,0);
/*hRet=lpDD->CreateClipper(NULL,&lpClip,NULL);
if(hRet != DD_OK)
{
ErrStr=Err_CreateClip;
return false;
}
lpClip->SetHWnd(0,hWnd);*/
ZeroMemory(&ddsd,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
ddsd.dwBackBufferCount=1;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;
hRet=lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
if(hRet != DD_OK)return false;
/////////GOOD UP TO HERE///////////
DDSCAPS2 ddscaps;
ddscaps.dwCaps=DDSCAPS_BACKBUFFER;
hRet=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBack);
if(hRet!=DD_OK)
{
MessageBox(hWnd,"This message gets called","Hmm",MB_OK);
return false;
}
/////////BREAK DOWN HERE///////////
//lpDDSPrimary->SetClipper(lpClip);
bInit=true;
GAME.SetWndData(&hWnd,&hInst);
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if(!GetMessage(&msg,NULL,0,0))return msg.wParam;
TranslateMessage(&msg);
DispatchMessage(&msg);
}else{
if(perf_flag)QueryPerformanceCounter((LARGE_INTEGER*)&cur_time);
else cur_time=timeGetTime();
if(cur_time>next_time)
{
time_elapsed=(cur_time-last_time)*time_scale;
last_time=cur_time;
GAME.Action();
SCREEN.DrawScreen(&GAME,&hWnd);
next_time=cur_time+time_count;
}
}
}
return(msg.wParam);
}