Thread: Visual Studio 2010 - DirectX compilation error.

  1. #1
    Registered User
    Join Date
    Sep 2011

    Visual Studio 2010 - DirectX compilation error.

    I've downloaded and installed DirectX SDK of 2010 July. Every feature was checked to be installed to the disk.
    I am trying to compile a code from a book, but I am getting this error:
    1>LINK : fatal error LNK1104: cannot open file 'd3dx9.lib'
    And here is the code:
    #include <windows.h>
    #include <d3d9.h>
    #include <time.h>
    #include <iostream>
    using namespace std;
    #pragma comment(lib,"d3d9.lib")
    #pragma comment(lib,"d3dx9.lib")
    //program settings
    const string APPTITLE = "Direct3D_Windowed";
    const int SCREENW = 1024;
    const int SCREENH = 768;
    //Direct3D objects
    LPDIRECT3D9 d3d = NULL; 
    bool gameover = false;
    //macro to detect key presses
    #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
     ** Game initialization function
    bool Game_Init(HWND window)
        MessageBox(window, "Game_Init", "BREAKPOINT", 0);
        //initialize Direct3D
        d3d = Direct3DCreate9(D3D_SDK_VERSION);
        if (d3d == NULL)
            MessageBox(window, "Error initializing Direct3D", "Error", MB_OK);
            return 0;
        //set Direct3D presentation parameters
        ZeroMemory(&d3dpp, sizeof(d3dpp));
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
        d3dpp.BackBufferCount = 1;
        d3dpp.BackBufferWidth = SCREENW;
        d3dpp.BackBufferHeight = SCREENH;
        d3dpp.hDeviceWindow = window;
        //create Direct3D device
        if (d3ddev == NULL)
            MessageBox(window, "Error creating Direct3D device", "Error", MB_OK);
            return 0;
        return true;
     ** Game update function
    void Game_Run(HWND hwnd)
        //make sure the Direct3D device is valid
        if (!d3ddev) return;
        //clear the backbuffer to bright green
        d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0), 1.0f, 0);
        //start rendering
        if (d3ddev->BeginScene())
            //do something?
            //stop rendering
            //copy back buffer on the screen
            d3ddev->Present(NULL, NULL, NULL, NULL);
        //check for escape key (to exit program)
        if (KEY_DOWN(VK_ESCAPE))
            PostMessage(hwnd, WM_DESTROY, 0, 0);
     ** Game shutdown function
    void Game_End(HWND hwnd)
        //display close message
        MessageBox(hwnd, "Program is about to end", "Game_End", MB_OK);
        //free memory
        if (d3ddev) d3ddev->Release();
        if (d3d) d3d->Release();
     ** Windows event handling function
    LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
        switch( msg )
            case WM_DESTROY:
                gameover = true;
                return 0;
        return DefWindowProc( hWnd, msg, wParam, lParam );
     ** Main Windows entry function
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
        //set the new window's properties
        //previously found in the MyRegisterClass function
        WNDCLASSEX wc;
        wc.cbSize = sizeof(WNDCLASSEX);         = 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(WHITE_BRUSH);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = APPTITLE.c_str();
        wc.hIconSm       = NULL;
        //create a new window
        //previously found in the InitInstance function
        HWND window = CreateWindow( APPTITLE.c_str(), APPTITLE.c_str(),
           SCREENW, SCREENH,
           NULL, NULL, hInstance, NULL);
        //was there an error creating the window?
        if (window == 0) return 0;
        //display the window
        ShowWindow(window, nCmdShow);
        //initialize the game
        if (!Game_Init(window)) return 0;
        // main message loop
        MSG message;
        while (!gameover)
            if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) 
        return message.wParam;

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    This suggests that you have not set up the IDE properly.
    Just as you have added an include path for the DirectX header files, you need to add an include path for the .lib files. They are located at the same place in the GUI, almost, so if you added an include path for headers, you should have no trouble finding it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Solved it... There was a misleading mistake in the book, and it's a 3rd edition. Well thanks anyway.
    Last edited by PieMonster; 09-04-2011 at 03:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio 2010 .exe help
    By omGeeK in forum Game Programming
    Replies: 4
    Last Post: 03-20-2011, 01:36 PM
  2. Replies: 2
    Last Post: 08-28-2010, 12:58 AM
  3. Visual Studio 2010 x64 compilation
    By n1mda in forum Windows Programming
    Replies: 1
    Last Post: 07-20-2010, 05:20 AM
  4. Windows 7 RC, Visual Studio 2010 Beta, Office 2010 beta, anyone in?
    By indigo0086 in forum A Brief History of
    Replies: 2
    Last Post: 05-20-2009, 01:57 PM