   createdevice failure, please help!
  Hi, I'm new to DirectX Programming and i'm getting an D3DERR_INVALIDCALL error when I try to create a device. Here is my code in it's entirety. Thanks!/////////////////////////////////////////////////////////////////////// Beginning Game Programming// Chapter 5// Getting Started with Direct X#include &lt;d3d9.h&gt;#include &lt;d3d9types.h&gt;#include &lt;time.h&gt;#define APPTITLE "Direct3D_Windowed"//function prototypesLRESULT WINAPI WinProc(HWND,UINT,WPARAM,LPARAM);ATOM MyRegisterClass(HINSTANCE);int Game_Init();void Game_Run();void Game_End();LPDIRECT3D9 d3d = NULL;LPDIRECT3DDEVICE9 d3ddev = NULL;HWND hWnd = NULL;//local variables//HWND global_hwnd;//HDC global_hdc;//the window event callback functionLRESULT WINAPI WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){   switch (message) {case WM_DESTROY:  Game_End();PostQuitMessage(0);break;    }return DefWindowProc(hWnd, message, wParam, lParam);}//helper function to set up the window propertiesATOM MyRegisterClass(HINSTANCE hInstance){    //create the window class structure    WNDCLASSEX wc;    wc.cbSize = sizeof(WNDCLASSEX);//fill the struct with info    wc.style    = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc   = (WNDPROC)WinProc;    wc.cbClsExtra = 0;    wc.cbWndExtra = 0;    wc.hInstance= hInstance;    wc.hIcon    = NULL;    wc.hCursor  = LoadCursor(NULL, IDC_ARROW);    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);    wc.lpszMenuName  = NULL;    wc.lpszClassName = APPTITLE;    wc.hIconSm  = NULL;    //set up the window with the class info    return RegisterClassEx(&wc);}//helper function to create the window and refresh it//entry point for a Windows programint WINAPI WinMain(HINSTANCE hInstance,    HINSTANCE hPrevInstance,    LPSTRlpCmdLine,    int  nCmdShow){    int done = 0;MSG msg;// register the classMyRegisterClass(hInstance);    // initialize application    //create a new window    hWnd = CreateWindow(  APPTITLE,    //window class  APPTITLE,    //title bar  WS_OVERLAPPEDWINDOW,   //window style  CW_USEDEFAULT,    //x position of window  CW_USEDEFAULT,    //y position of window  500,    //width of the window  400,    //height of the window   NULL,   //parent window  NULL,   //menu  hInstance,   //application instance  NULL);  //window parameters    //was there an error creating the window?    if (!hWnd) return FALSE;    //display the window    ShowWindow(hWnd, nCmdShow);    UpdateWindow(hWnd);    //initialize the game    if(!Game_Init())return 0;    // main message loopwhile (!done){   if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))    {  //look for quit message  if (msg.message == WM_QUIT)  {MessageBox(hWnd,"Recieved WM_QUIT message", "WinMian",MB_OK);done = 1;}  //decode and pass messages on to WndProc  TranslateMessage(&msg);    DispatchMessage(&msg);   } //process game loop (else prevents running after window is closed)   Game_Run();}return msg.wParam;}int Game_Init(){    //initialize the game...    //load bitmaps, meshes, textures, sounds, etc.//display init messageMessageBox(hWnd, "Program is about to start","Game_Init", MB_OK);//initialize Direct3Dd3d = Direct3DCreate9(D3D_SDK_VERSION);if(d3d == NULL){MessageBox(hWnd,"Error initializing Direct3D", "Error", MB_OK);return 0;}//set Direct3D presentation parametersD3DPRESENT_PARAMETERS d3dpp;ZeroMemory(&d3dpp, sizeof(d3dpp));d3dpp.Windowed = TRUE;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;//create Direct3D deviceif((d3d-&gt;CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev)) == D3DERR_INVALIDCALL){MessageBox(hWnd,"D3DERR_INVALIDCALL","Error",MB_OK);}if(d3ddev == NULL){MessageBox(hWnd, "Error creating Direct3D device1", "Error", MB_OK);return 0;}//set random number seed    srand(time(NULL));return 1;}void Game_Run(){    //make sure the Direct3D device is validif(d3ddev == NULL)return;//clear the backbuffer with a green colord3ddev-&gt;Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,255,255),1.0f,0);//start renderingif(d3ddev-&gt;BeginScene()){//do something here!//stop renderingd3ddev-&gt;EndScene();}//display the back buffer on the screend3ddev-&gt;Present(NULL,NULL,NULL,NULL);}void Game_End(){//display close messageMessageBox(hWnd,"Program is about to end", "Game_end",MB_OK);//release the Direct3D deviceif(d3ddev != NULL)d3ddev-&gt;Release();//release the Direct3D objectif(d3d != NULL)d3d-&gt;Release();}/////////////////////////////////////////////////////////////////////[Edited by - jollyjeffers on May 27, 2006 12:30:13 PM]
  The INVALIDCALL result doesn't tell you much about whats wrong. Since you'll be hitting them a lot in your future development (yes I guarantee :p) you better know how to deal with them not just in this particular situation.Go to you control panel and spot the "directX" icon. Tick "use debug version of D3D" and set the output level to the max. Then you're likely going to know what you've messed. Watch carfully the debug output of visual studio (assumon you're using that IDE)BTW, checking == D3DERR_INVALIDCALL is not generally speaking something as good as using SUCCEEDED and FAILED macros, because DirectX error code are not limited to D3DERR_INVALIDCALL(and use [ source ] [ / source ] tags ;), removing the extra spaces)I hop that will help ;)Regards, Janta   ;Quote:Original post by jantaThe INVALIDCALL result doesn't tell you much about whats wrong. Since you'll be hitting them a lot in your future development (yes I guarantee :p) you better know how to deal with them not just in this particular situation.Go to you control panel and spot the "directX" icon. Tick "use debug version of D3D" and set the output level to the max. Then you're likely going to know what you've messed. Watch carfully the debug output of visual studio (assumon you're using that IDE)You can also check out the "DirectX Debugging" link in my signiture for more details...Quote:Original post by janta(and use [ source ] [ / source ] tags ;), removing the extra spaces)I've corrected it for you - just remember for next time please [wink]I can't see anything obviously wrong with your code; so the debug runtime output would be useful.I also suggest you run and look at the 1st D3D tutorial in the SDK: \Samples\C++\Direct3D\Tutorials\Tut01_CreateDevice\.If that has the same errors (also check some other SDK samples) then it could possibly be something wrong with your drivers. I'd be surprised if this was the case - but maybe you've not got a D3D9 compatable hardware/driver combo.hthJack   ;  Thanks for the help. I set the Debug output level to the highest setting, however, I do not see a debug output window. Is that something I have to specify in Visual C++. Also, I am using Visual C++ 6.0. Lastly, what does this mean..."(and use [ source ] [ / source ] tags ;), removing the extra spaces)"Thanks again!~Brian Wright;Quote:Original post by FlyrunI do not see a debug output window. Is that something I have to specify in Visual C++.It should be there somewhere. Been a long time since I've used VC6, but dig around in the view menu's - I think its only referred to as the "output" window/pane. Might well be hidden behind one of the tabs though - so make sure you check those.Quote:Original post by FlyrunAlso, I am using Visual C++ 6.0.VC6 hasn't been a supported IDE for well over a year. You'll need an older SDK (one from 2004 or earlier) or theres a good chance you'll start to get all sorts of crazy problems [smile]Try the Visual C++ 2005 Express Edition - it's free and a million times better than VC6.Quote:Original post by FlyrunLastly, what does this mean..."(and use [ source ] [ / source ] tags ;), removing the extra spaces)"The forum software here uses [source]...[/source] tags to mark blocks of code - you'll get the scrolling text-area as seen in your original post.As per the forum guidelines, dumping a big listing of code isn't A Good Thing™, so I prefer it if people wrap things up in appropriate tags [smile]Cheers,Jack   ;  I found the output/debug window. This is the message it is giving me, which I do not understand. Does anybody know what this means?oaded symbols for 'C:\My Documents\Brian\GAMES\Chapter5\Debug\Chapter5.exe'Loaded 'C:\WINDOWS\SYSTEM\d3d9d.dll', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\d3d9.dll', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\WINMM.DLL', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\DDRAW.DLL', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\NTDLL.DLL', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\VERSION.DLL', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\USER32.DLL', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\GDI32.DLL', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\ADVAPI32.DLL', no matching symbolic information found.Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL', no matching symbolic information found.;Quote:Original post by FlyrunThis is the message it is giving me, which I do not understand. Does anybody know what this means?Doesn't really mean a whole lot beyond the fact that you haven't got any symbols installed/configured. I get pretty much the same thing with my IDE.You have found the correct place though - if you've got the debug runtimes enabled the D3DX/D3D debug output should start appearing below the messages you've quoted. Are you getting nothing for the entire duration of your application? Have you enabled the debug runtimes as shown in the NeXe article I mentioned above?Jack   ;  I was able to build the code you posted successfully using VS2005 Pro.  CreateDevice doesn't fail when I run the app, however inside Game_Run there's a problem with:if (d3ddev->BeginScene())That line should be:if (SUCCEEDED(d3ddev->BeginScene()))Since BeginScene returns an HRESULT, it will return zero when it succeeds and your code seems to expect the opposite.If this code came from a book, please tell me the title/author of it so I can make sure that I don't recommend it to anyone who is trying to learn Direct3D programming.;  In the create d3ddevice code, try changing D3DEVTYPE_HAL to D3DEVTYPE_REF and see if that helps.   ;  I tried those statements and they seemed to not have worked. The book that i'm getting the code for actually uses VC6, and I even copied and pasted the code from the book and it gave me the same error. I'm running Windows ME, so I don't know if that has something to do with it either. I also ran the test on my machine and they all work, so it couldn't be the drivers...Does anybody have any other ideas?   