Direct 3D Device Pointer

Can anyone tell why I can't get a D3DDevice pointer?
Here's my code.
The switch statement returns a D3DERR_INVALIDCALL case; can anyone tell me why?

I'm just starting to program in MFC and Directx.

#include
#include
#include

void InitDXParam(D3DPRESENT_PARAMETERS*, D3DDISPLAYMODE*);

class MainApp : public CWinApp
{
public:
virtual BOOL InitInstance();

};

MainApp mainApp;

BOOL MainApp::InitInstance()
{
CFrameWnd *mainWindow=new CFrameWnd;
m_pMainWnd=mainWindow;
mainWindow->Create(NULL, "Direct X");
mainWindow->ShowWindow(m_nCmdShow);
mainWindow->UpdateWindow();
HWND hwnd=m_pMainWnd->GetSafeHwnd();

IDirect3D8 *d3dp=NULL;
D3DDISPLAYMODE d3ddis;
D3DPRESENT_PARAMETERS d3dparam;
LPDIRECT3DDEVICE8 d3ddevice;
d3dp=Direct3DCreate8(D3D_SDK_VERSION);
HRESULT hResult;

if(&d3dp!=NULL)
d3dp->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddis);

if(&d3ddis!=NULL)
InitDXParam(&d3dparam, &d3ddis);

hResult=d3dp->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dparam, &d3ddevice);

switch(hResult)
{
case D3D_OK:
MessageBox(NULL, "1",NULL , MB_OK);
break;
case D3DERR_INVALIDCALL:
MessageBox(NULL, "2",NULL , MB_OK);
return FALSE;
break;
case D3DERR_NOTAVAILABLE:
MessageBox(NULL, "3",NULL , MB_OK);
return FALSE;
break;
};

if(d3ddevice!=NULL)
d3ddevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

return TRUE;
}

void InitDXParam(D3DPRESENT_PARAMETERS *d3dparam, D3DDISPLAYMODE *d3ddis)
{
ZeroMemory(d3dparam, sizeof(d3dparam));
(*d3dparam).Windowed = TRUE;
(*d3dparam).SwapEffect = D3DSWAPEFFECT_DISCARD;
(*d3dparam).BackBufferFormat = (*d3ddis).Format;
}
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories