   Is something wrong with my d3d class?
  I wrote a windows class and it works fine and then i wrote a direct3d initializing class, it compiles fine but afterwards i get a windows error as soon as the program starts up. Here is my D3D Class code:   #include<windows.h>#include<d3d9.h>#include<d3dx9.h>#include<EZWindow.h>#pragma comment(lib,"d3d9.lib")#pragma comment(lib,"d3dx9.lib")class D3DWindow{private:IDirect3D9 *pd3d;IDirect3DDevice9 *pd3dd;D3DPRESENT_PARAMETERS d3dpp;D3DDISPLAYMODE d3ddm;public:D3DWindow(HWND hWnd, int SIZEX,int SIZEY){pd3d = Direct3DCreate9(D3D_SDK_VERSION);pd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);d3ddm.Width = SIZEX;d3ddm.Height = SIZEY;d3ddm.RefreshRate = 0;d3ddm.Format = D3DFMT_R5G6B5;ZeroMemory(&d3dpp,sizeof(d3dpp));d3dpp.Windowed = false;d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dpp.BackBufferFormat = d3ddm.Format;d3dpp.EnableAutoDepthStencil = FALSE;pd3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dd);}~D3DWindow(){if(pd3d != NULL){pd3d->Release();pd3d = NULL;}if(pd3dd != NULL){pd3dd->Release();pd3dd = NULL;}}BOOL DisplayScene(){pd3dd->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_RGBA(0,64,128,255),1.0f,0);pd3dd->BeginScene();pd3dd->EndScene();pd3dd->Present(NULL,NULL,NULL,NULL);return true;}};/*LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam){switch(iMsg){case WM_DESTROY:PostQuitMessage(0);break;}}*/int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hpInstance,PSTR cmdLine,int iCmd){AppWindow window(hInstance,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));D3DWindow d3d(window.GetWinHwnd(),GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));while(1){if(PeekMessage(&window.GetWinMessage(),NULL,0,0, PM_REMOVE)){TranslateMessage(&window.GetWinMessage());DispatchMessage(&window.GetWinMessage());} else {d3d.DisplayScene();} }return 0;}And here is my windows class:   #include <windows.h>LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);class AppWindow{private:HWND hwnd;MSG msg;WNDCLASS wc;public:AppWindow(HINSTANCE hinst){wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wc.hCursor = LoadCursor(NULL,IDC_ARROW);wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);wc.hInstance = hinst;wc.lpfnWndProc = WndProc; // global procwc.lpszClassName = "Class";wc.lpszMenuName = NULL;wc.style = CS_VREDRAW|CS_HREDRAW;RegisterClass(&wc);hwnd = CreateWindow("Class","Window",WS_OVERLAPPEDWINDOW,0,0,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hinst,NULL);}AppWindow(HINSTANCE hinst,int sizex,int sizey){wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wc.hCursor = LoadCursor(NULL,IDC_ARROW);wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);wc.hInstance = hinst;wc.lpfnWndProc = WndProc;wc.lpszClassName = "Class";wc.lpszMenuName = NULL;wc.style = CS_VREDRAW|CS_HREDRAW;RegisterClass(&wc);hwnd = CreateWindow("Class","Window",WS_OVERLAPPEDWINDOW,0,0,sizex,sizey,NULL,NULL,hinst,NULL);}AppWindow(HINSTANCE hinst,int locx,int locy,int sizex,int sizey){wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);wc.hCursor = LoadCursor(NULL,IDC_ARROW);wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);wc.hInstance = hinst;wc.lpfnWndProc = WndProc;wc.lpszClassName = "Class";wc.lpszMenuName = NULL;wc.style = CS_VREDRAW|CS_HREDRAW;RegisterClass(&wc);hwnd = CreateWindow("Class","Window",WS_OVERLAPPEDWINDOW,locx,locy,sizex,sizey,NULL,NULL,hinst,NULL);}static LRESULT CALLBACK AppWndProc(HWND hwnd,UINT imsg, WPARAM wParam,LPARAM lParam){switch(imsg){case WM_DESTROY:PostQuitMessage(0);break;}return DefWindowProc(hwnd,imsg,wParam,lParam);}    void Display(int i){UpdateWindow(hwnd);ShowWindow(hwnd,i);while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}}MSG GetWinMessage(){return msg;}HWND GetWinHwnd(){return hwnd;}};I have no idea what could be wrong because it is a runtime error.Soon as the program starts i get the error message. Thanks ahead guys,Cory   Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|    
  Is 0 Refresh Rate even a valid assignment? It''s the only thing that really stood out to me.Also you should really take the time to generalize your setup. Do searches for the parameters you want to set and try and find a match that best fits the display mode you desire. ;  What error do you get? ;  It''s a run time sorry for the inconvienience error. From windows.   Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|;  Hm.. are you building in debug mode (I assume you''re using visual studio)?  Sometimes you get more error info if you run under the debug configuration than under release. ;  Yep, visual studio, i tried release and debug still the same thing. I even sent the release to a buddy, it did the same thing for him.   Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|;  I used the debugger and it''s in the directx code for sure.   Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|;  You''ve got so many problems with this code, I don''t know where to start.  I would encourage you to toss this and start with some of the code in the D3D9 SDK samples but if you insist on keeping it... You haven''t checked a *SINGLE* API call for failure!  It is beyond my comprehension how someone could ask for help and post code and none of the code contain any sort of error checking to detect an API failure.You should never make API calls in a constructor that have the capability of failing because you have no way to return an error to the caller that instantiated the class (unless you''re goign to throw a C++ exception).Your message handler will never work because window.GetWinMessage is returning a copy of the class'' MSG struct, thus what PeekMessage is writing to won''t be what TranslateMessage and DispatchMessage will be using.Your message handler has no way to exit the while(1) loop.IDirect3D9::CreateDevice will fail because you haven''t initialized the D3DPRESENT_PARAMETERS struct properly.  You''re initializing values of D3DDISPLAYMODE (d3ddm) *AFTER* you''ve called GetAdapterDisplayMode to initialize the struct.You can debug this code (once you uncomment the WndProc so that it will build) by setting a breakpoint at WinMain, then running the program in the debugger.  When the debugger breaks at the breakpoint, then start stepping into your class constructors until things fault.  There''s no point of doing this though until you fix the problems I''ve listed above.  You should also install the D3D9 debug runtime DLLs.  They perform a lot more error checking and will send detailed output to debugger''s output window when something fails inside D3D.Good luck.