   Is my error hadling working?
  I have written a program that is supposed to play a 3 frame animation in the upper corner of the screen.This is my program, for some reason sometimes when it compiles it saws link error, cannot open file ''libci.lib'', but sometimes it works. Other times when it compiles properly the screen just goes black and then the program exits, i have a feeling this is due to shitty error handling. can you plz find out wuts wrong, thanx.//////////////////////////////////////////////////////// BasicDirect3DApp//////////////////////////////////////////////////////#include <windows.h>#include <d3d8.h>#include <d3dx8tex.h>// Function prototypes.LRESULT WINAPI WndProc(HWND hWnd, UINT msg,    WPARAM wParam, LPARAM lParam);void RegisterWindowClass(HINSTANCE hInstance);void CreateAppWindow(HINSTANCE hInstance);WPARAM StartMessageLoop();HRESULT InitFullScreenDirect3D();HRESULT InitDirect3D();HRESULT CreateSurfaces();void Render();void CleanUpDirect3D();// Global variables.HWND g_hWnd;char g_ErrorMsg[256];HRESULT g_hResult = D3D_OK;IDirect3D8* g_pDirect3D = NULL;IDirect3DDevice8* g_pDirect3DDevice = NULL;IDirect3DSurface8* g_pBitmapSurfaces[3];//////////////////////////////////////////////////////// WinMain()//////////////////////////////////////////////////////INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT){    RegisterWindowClass(hInstance);    CreateAppWindow(hInstance);    ShowWindow(g_hWnd, SW_SHOWDEFAULT);    UpdateWindow(g_hWnd);    HRESULT hResult = InitFullScreenDirect3D();    if (SUCCEEDED(hResult))    WPARAM result = StartMessageLoop();    CleanUpDirect3D();    return 0;}//////////////////////////////////////////////////////// WndProc()//////////////////////////////////////////////////////LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){    switch(msg)    {    case WM_CREATE:   return 0;    case WM_DESTROY:   PostQuitMessage( 0 );   return 0;    case WM_PAINT:   ValidateRect(g_hWnd, NULL);   return 0;    case WM_KEYDOWN:   switch(wParam)   {  case VK_ESCAPE: PostQuitMessage(WM_QUIT); break;   }    }    return DefWindowProc(hWnd, msg, wParam, lParam);}//////////////////////////////////////////////////////// RegisterWindowClass()//////////////////////////////////////////////////////void RegisterWindowClass(HINSTANCE hInstance){    WNDCLASSEX wc;    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;    wc.lpfnWndProc = WndProc;    wc.cbClsExtra = 0;    wc.cbWndExtra = 0;wc.hInstance = hInstance;    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);    wc.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);    wc.lpszMenuName = NULL;    wc.lpszClassName = "Direct3DApp";    wc.hIconSm = NULL;    RegisterClassEx(&wc);}//////////////////////////////////////////////////////// CreateAppWindow()//////////////////////////////////////////////////////void CreateAppWindow(HINSTANCE hInstance){    g_hWnd = CreateWindowEx(   NULL,   "Direct3DApp",   "Basic Direct3D Application",    WS_OVERLAPPEDWINDOW,   100,   100,   648,   514,   GetDesktopWindow(),   NULL,   hInstance,   NULL);}//////////////////////////////////////////////////////// StartMessageLoop()//////////////////////////////////////////////////////WPARAM StartMessageLoop(){    MSG msg;    while(1)    {   if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {  if (msg.message == WM_QUIT) break;  TranslateMessage(&msg;  DispatchMessage(&msg;   }   else   {    Render();   }    }    return msg.wParam;}//////////////////////////////////////////////////////// InitFullScreenDirect3D()//////////////////////////////////////////////////////HRESULT InitFullScreenDirect3D(){HRESULT hResult = InitDirect3D();if(FAILED(hResult)){return hResult;}hResult = CreateSurfaces();if(FAILED(hResult)){return hResult;}return D3D_OK;}//////////////////////////////////////////////////////// CleanUpDirect3D()//////////////////////////////////////////////////////void CleanUpDirect3D(){    if (g_pDirect3DDevice)   g_pDirect3DDevice->Release();    if (g_pDirect3D)   g_pDirect3D->Release();}////////////////////////////////////////////////////////InitDirect3D();//////////////////////////////////////////////////////HRESULT InitDirect3D(){    g_pDirect3D = Direct3DCreate8(D3D_SDK_VERSION);    if (g_pDirect3D == NULL)   return E_FAIL;    HRESULT hResult = g_pDirect3D->CheckDeviceType(D3DADAPTER_DEFAULT,   D3DDEVTYPE_REF, D3DFMT_X8R8G8B8, D3DFMT_X8R8G8B8, FALSE);    if (hResult != D3D_OK)    {   MessageBox(g_hWnd,  "Sorry. This program won’t\nrun on your system.",  "DirectX Error", MB_OK);   return E_FAIL;    }    D3DPRESENT_PARAMETERS D3DPresentParams;    ZeroMemory(&D3DPresentParams, sizeof(D3DPRESENT_PARAMETERS));    D3DPresentParams.Windowed = FALSE;    D3DPresentParams.BackBufferCount = 1;    D3DPresentParams.BackBufferWidth = 800;    D3DPresentParams.BackBufferHeight = 600;    D3DPresentParams.BackBufferFormat = D3DFMT_X8R8G8B8;    D3DPresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;    D3DPresentParams.hDeviceWindow = g_hWnd;    hResult = g_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT,    D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,    &D3DPresentParams, &g_pDirect3DDevice);    if (FAILED(hResult))   return E_FAIL;    return D3D_OK;}////////////////////////////////////////////////////////CreateSurfaces();//////////////////////////////////////////////////////HRESULT CreateSurfaces(){char Filename[20];for(int i = 0; i < 3; ++i){HRESULT hResult = g_pDirect3DDevice->CreateImageSurface(50, 50, D3DFMT_X8R8G8B8, &g_pBitmapSurfaces);if(FAILED(hResult)){strcpy(g_ErrorMsg, "Error Creating Image Surface.");return hResult;}wsprintf(Filename, "%s%d%s", "Anim", i, ".bmp");hResult = D3DXLoadSurfaceFromFile(g_pBitmapSurfaces, NULL, NULL, Filename, NULL, D3DX_DEFAULT, 0, NULL);if(FAILED(hResult)){strcpy(g_ErrorMsg, "Error loading image to surface.");return hResult;}}return D3D_OK;}///////////////////////////////////////////////////////Render();/////////////////////////////////////////////////////////void Render(){static int framenum = 0;IDirect3DSurface8* pBackBuffer = NULL;g_hResult = g_pDirect3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);if(FAILED(g_hResult)){strcpy(g_ErrorMsg, "Error getting back buffer.");PostQuitMessage(WM_QUIT);return;}RECT SrcRect;SrcRect.left = 0;SrcRect.right = 50;SrcRect.top = 0;SrcRect.bottom = 50;POINT DstPoint;DstPoint.x = 0;DstPoint.y = 0;g_hResult = g_pDirect3DDevice->CopyRects(g_pBitmapSurfaces[framenum], &SrcRect, 1, pBackBuffer, &DstPoint);if(FAILED(g_hResult)){strcpy(g_ErrorMsg, "Error copying image to backbuffer.");PostQuitMessage(WM_QUIT);return;}g_pDirect3DDevice->Present(NULL, NULL, NULL, NULL);framenum = framenum + 1;if(framenum == 4){framenum = 0;}}  </i>  