Why does CreateDevice() fail?

Started by
20 comments, last by Ice-T 20 years, 8 months ago
For some reason, CreateDevice() always fails for me in Direct3D 9. I know I installed DirectX 9 properly so why is not working? Direct3D_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, VertexProcessing, &Present_Parameters, &D3D_Device)
Advertisement
we''ll need a bit more info than that
End Of Discussion.
With the code you posted, we need to know this : hWnd, Present_Parameters, and VertexProcessing to know whats up, and to make sure you initialized your Device to NULL.


Thanks!

-Rhone
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
Sorry about that. Here's the code. There's no reason why it shouldn't work. It was a sample with the DirectX9 SDK.


#include <d3d9.h>

LPDIRECT3D9 g_pD3D = NULL; LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;

HRESULT InitD3D( HWND hWnd )
{

if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;


if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}



return S_OK;
}



VOID Cleanup()
{
if( g_pd3dDevice != NULL)
g_pd3dDevice->Release();

if( g_pD3D != NULL)
g_pD3D->Release();
}




VOID Render()
{
if( NULL == g_pd3dDevice )
return;


g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );


if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{



g_pd3dDevice->EndScene();
}


g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}





LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;

case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
}

return DefWindowProc( hWnd, msg, wParam, lParam );
}




INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{

WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"D3D Tutorial", NULL };
RegisterClassEx( &wc );


HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial 01: CreateDevice",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
GetDesktopWindow(), NULL, wc.hInstance, NULL );


if( SUCCEEDED( InitD3D( hWnd ) ) )
{
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );


MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}

UnregisterClass( "D3D Tutorial", wc.hInstance );
return 0;
}


[edited by - Ice-T on August 14, 2003 12:03:28 AM]
d3dpp.hDeviceWindow = hWnd;
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
Grab the exact error code with an HRESULT variable and run it through DXGetErrorString9 or DXGetErrorDescription9 and pop those in a message box. That oughta clear things up.
did you create your window before you tried to pass it to the CreateDevce?
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
quote:Original post by RhoneRanger
did you create your window before you tried to pass it to the CreateDevce?


Yah. And the error description I got was D3DERR_INVALIDCALL and "Invalid Call". What should I do since it doesn't recognize the call? Does it mean DirectX 9 is improperly installed? It compiles and links fine.

Just wondering, did the code work for you guys?



[edited by - Ice-T on August 15, 2003 1:20:57 AM]
If you have the debug version of DirectX installed it will tell you what''s wrong. If you don''t have it installed, go do it.

Then go to the control panel and click the DirectX icon. Go to the Direct3D tab and crank the error level. Now when you run your DirectX apps all sorts of interesting information will be dumped into the debug window.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
quote:Original post by DrunkenHyena
If you have the debug version of DirectX installed it will tell you what's wrong. If you don't have it installed, go do it.

Then go to the control panel and click the DirectX icon. Go to the Direct3D tab and crank the error level. Now when you run your DirectX apps all sorts of interesting information will be dumped into the debug window.


No luck with that either. So does anybody have any suggestions?


[edited by - Ice-T on August 15, 2003 2:38:58 AM]

This topic is closed to new replies.

Advertisement