   Error Handling Fail
  Hey there again forum, I was adding in error handling code to my program the code works fine without the error handling but the error handling seems keen to throw an error without any explanation, thats where I hope some of you can come in.// Create Direct3D and the Direct3D Devicevoid InitDirect3D(GAMEWINDOW* gw){    if(FAILED(d3d = Direct3DCreate9(D3D_SDK_VERSION)))    {   MessageBox(NULL, "The Direct3DCreate function failed, restart program to try and resolve error, please contact Dom and tell him what happened.", "Error", MB_OK);   PostQuitMessage(0);    }    ZeroMemory(&d3dpp, sizeof(d3dpp));    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    d3dpp.Windowed = gw->Windowed;    d3dpp.BackBufferWidth = gw->Width;    d3dpp.BackBufferHeight = gw->Height;//Heres the bit that is giving me trouble it always throws an error!    if(FAILED(d3d->CreateDevice(D3DADAPTER_DEFAULT,  D3DDEVTYPE_HAL,  gw->hWnd,  D3DCREATE_HARDWARE_VERTEXPROCESSING,  &d3dpp,  &d3ddev)));{   MessageBox(NULL, "The CreateDevice function failed, restart program to try and resolve error, please contact Dom and tell him what happened.", "Error", MB_OK);   PostQuitMessage(0);    }    if(FAILED(D3DXCreateFont(d3ddev,    // the D3D Device30,    // font height of 300,    // default font widthFW_NORMAL,    // font weight1,    // not using MipLevelstrue,    // italic fontDEFAULT_CHARSET,    // default character setOUT_DEFAULT_PRECIS,    // default OutputPrecision,ANTIALIASED_QUALITY,    // highest QualityDEFAULT_PITCH | FF_DONTCARE,    // default pitch and family"Arial",    // use Facename Arial&dxfont)));    // the font object{   MessageBox(NULL, "The CreateFont function failed, restart program to try and resolve error, please contact Dom and tell him what happened.", "Error", MB_OK);   PostQuitMessage(0);    }    D3DXCreateSprite(d3ddev, &d3dspt);    return;}If I leave this code to its own operation it says that CreateDevice failed, even though I am certain it worked. In addition to adding in this code I also added in code to reset my devices if the window looses function but even when I disable that code this stuff still claims it has failed. I dont know why FAILED is returning true.I tried to resolve the problem myself by analysing the value returned by FAILED to do this I threw its returned expression into a LPCSTR it was just '0' and I also attempted to watch it but got a compiler error saying the symbol was not recognised. How can I find out what is happening here?   
  FAILED should only be used with functions that return an HRESULT. Most DirectX functions do this, but not Direct3DCreate9(). That one returns a pointer. To see if it succeeds, just check if the pointer it returns is not NULL.By the way, you should also check the call to D3DXCreateSprite().   ;  And by the way: PostQuitMessage() does NOT end the programm. It simply posts a quit message which you will receive in your message loop. The InitDirect3D function will continue as if no error occured. Which will lead to crashes a few lines later when you use the "d3d" pointer for the first time.At least put a "return" behind each PostQuitMessage. But usually you just signal back to the caller that the function has failed. You can do this by throwing an exception, or by returning a bool stating the success of the call.   ;  thankyou I will put that together but this greatly confuses me I grasped my understanding of this error code from a tutorial website! that was actually used in the tutorial, I guess they are out of date to say the least. I am curious as to if im missing something, I have looked over tutorials on the web to compare to the ones I am learning from primarily and have noticed theres a massive difference in the resetting of the device.// Reset the Devicevoid ResetDevice(){    if(d3ddev){d3dspt->OnLostDevice();dxfont->OnLostDevice();   d3ddev->Reset(&d3dpp);   d3dspt->OnResetDevice();   dxfont->OnResetDevice();}    return;}Theres my code in a nutshell am I doing something wrong by not releasing and reloading the textures / meshes as I have seen in another tutorial when resetting the device, im not sure which code to trust for efficiency reliability and ensuring theres no memory leaks.   ;  I will add that return code in too, its odd that this tutorial I got was so very sketchy on the details! Thanks guys   ;  There added a function call so it clears up before returning that its failed. Also put my release code into if statements so it doesnt try to release something that isnt there.  // Create Direct3D and the Direct3D Devicevoid InitDirect3D(GAMEWINDOW* gw){    if(FAILED(d3d = Direct3DCreate9(D3D_SDK_VERSION)))    {   MessageBox(NULL, "The Direct3DCreate function failed, please contact Dom and tell him what happened, restart and give the game another go.", "Error", MB_OK);   PostQuitMessage(0);CloseDirect3D();return;    }    ZeroMemory(&d3dpp, sizeof(d3dpp));    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    d3dpp.Windowed = gw->Windowed;    d3dpp.BackBufferWidth = gw->Width;    d3dpp.BackBufferHeight = gw->Height;    d3d->CreateDevice(D3DADAPTER_DEFAULT,  D3DDEVTYPE_HAL,  gw->hWnd,  D3DCREATE_HARDWARE_VERTEXPROCESSING,  &d3dpp,  &d3ddev);if (d3d == NULL){   MessageBox(NULL, "The Direct3DCreate function failed, please contact Dom and tell him what happened, restart and give the game another go.", "Error", MB_OK);   PostQuitMessage(0);CloseDirect3D();return;}    D3DXCreateFont(d3ddev,    // the D3D Device30,    // font height of 300,    // default font widthFW_NORMAL,    // font weight1,    // not using MipLevelstrue,    // italic fontDEFAULT_CHARSET,    // default character setOUT_DEFAULT_PRECIS,    // default OutputPrecision,ANTIALIASED_QUALITY,    // highest QualityDEFAULT_PITCH | FF_DONTCARE,    // default pitch and family"Arial",    // use Facename Arial&dxfont);    // the font objectif (dxfont == NULL){   MessageBox(NULL, "The Direct3DFont function failed, please contact Dom and tell him what happened, restart and give the game another go.", "Error", MB_OK);   PostQuitMessage(0);CloseDirect3D();return;}    D3DXCreateSprite(d3ddev, &d3dspt);if (d3dspt == NULL){   MessageBox(NULL, "The Direct3DSprite function failed, please contact Dom and tell him what happened, restart and give the game another go.", "Error", MB_OK);   PostQuitMessage(0);CloseDirect3D();return;}    return;}in Close Direct 3D it is all ready to be released if it exists // Close the Device and Direct3Dvoid CloseDirect3D(){if (dxfont != NULL){dxfont->Release();}if (d3dspt != NULL){d3dspt->Release();}if (d3ddev != NULL){d3ddev->Release();}if (d3d != NULL){d3d->Release();}    return;}Thanks again for your help I your both getting positive feedback! [smile]   