   Compiles ok, but doesn't work!
  I wrote a directx class and a windows class and i tried to use them but when i did during the execution i got a windows error.I have no Idea why. Here''s my code for both of the files.   #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;}};#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;}Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|    
  *cough* for being a member since 2002...What is the error? ;  cough windows error. NOt compile time! It just gives a sorry for the inconvienience messages.   Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|;  ...?So what are you saying.It crashes? "Windows error" doesn''t mean much, there are lots of "windows errors". Does it crash? Does it give unexpected results? Does it just plain not do anything? ;  Just gives the windows must shut down this program message box. It doesn''t give specifics.   Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|;  When do you get the error?  Can you see a window being created then destroyed?I think your problem might be in the  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);}not sure though.. I thin kyou need to handle more then just WM_DESTROY.   [edited by - MrBeaner on February 17, 2004 11:30:47 PM];  If you add some error checking to your code it might be easier to find the error. Using a debugger to step through to certain breakpoints would help to isolate the problem as well. As it is now, it seems like you are using a bad pointer.   Colin Jeanne | Invader''s Realm"I forgot I had the Scroll Lock key until a few weeks ago when some asshole program used it. It even used it right" - Conner McCloud 