Thread: directx sdk samples not working

  1. #16
    Registered User
    Join Date
    May 2010
    Posts
    28
    Okay. Yes, I see it. DXSETUP.exe

    Installed with no problems.

    I'll go ahead and try to run my proggie and see what happens.

  2. #17
    Registered User
    Join Date
    May 2010
    Posts
    28
    And here are my errors,

    1>------ Build started: Project: autodidac_dx_2, Configuration: Debug Win32 ------
    1> prog.cpp
    1>prog.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "void __cdecl initD3D(struct HWND__ *)" (?initD3D@@YAXPAUHWND__@@@Z)
    1>prog.obj : error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
    1>prog.obj : error LNK2019: unresolved external symbol _D3DXMatrixLookAtLH@16 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
    1>prog.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationY@8 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
    1>C:\Documents and Settings\Rian Saville\My Documents\Visual Studio 2010\Projects\autodidac_dx_2\Debug\autodidac_dx_2. exe : fatal error LNK1120: 4 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Could this be because I didn't install the symbol files?

  3. #18
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No that is b/c you aren't linking with the export libraries.

    You will need to add these lines for your linker.

    d3d9.lib
    d3dx9.lib (release) or d3dx9d.lib (debug)
    dxguid.lib (this has all the GUIDs for the interfaces)

    For MSVC you add those lines in Linker->Input->Additional Dependencies

    Direct3DCreate9() is in d3d9.lib
    All the other unresolved externals you are getting are in d3dx9.lib and d3dx9d.lib

    If you are linking with the debug version of D3DX (d3dx9d.lib) you should also define D3D_DEBUG_INFO in your pre-processor settings. Additionally you will want to run dxcpl.exe (Program Files->Microsoft DirectX SDK (month year)->DirectX Utilities->DirectX Control Panel) and set the Debug output level to about halfway for Direct3D, DirectInput, and DirectSound (if you use the last two). This will give you some valuable debugging information when developing your Direct3D application. Also you will want to set each of them to use the Debug version of their DLLs. Note that before running any retail game you will want to set these back to retail versions or your game will run like garbage. For other debugging you may want to use maximum validation, break on memory leaks, etc. Break on memory leaks is valid b/c if you set this the DirectX runtimes will break on a COM resource leak. Also when Direct3D exits and if your debug output level is high enough you will get resource allocation IDs for each allocation. If you set the control panel to break on memory leaks and type the allocation ID in the Alloc ID text field your application will break on the line of code that is allocating a resource that has the ID. Very helpful for finding memory leaks.

    Keep in mind that Direct3D is a hard beast to debug b/c if you leak ANY resource along the way the entire device will leak and dump tons of leaks to std::out even though it may have been caused by one leak.
    Last edited by VirtualAce; 06-29-2010 at 01:23 PM.

  4. #19
    Registered User
    Join Date
    May 2010
    Posts
    28
    I did as you suggested. I'm using MSVS 2010 Express and I placed those files in additional dependencies each on it's own line. It returned one error.

    1>LINK : fatal error LNK1104: cannot open file 'd3dx9.lib'


    BTW, here is my code if it helps. It's from an online DX tutorial: just a simple program to display a rotating triangle.

    Code:
    // include the basic windows header files and the Direct3D header file
    #include <windows.h>
    #include <windowsx.h>
    #include <d3d9.h>
    #include <d3dx9.h>
    
    //#pragma comment (lib, "d3d9.lib")  // D3D library
    //#pragma comment (lib, "d3dx9.lib") // D3DX library
    
    // define the screen resolution
    #define SCREEN_WIDTH 800
    #define SCREEN_HEIGHT 600
    
    // include the Direct3D Library files
    //#pragma comment (lib, "d3d9.lib")
    //#pragma comment (lib, "d3dx9.lib")
    
    // global declarations
    LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
    LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class
    LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;    // the pointer to the vertex buffer
    
    // function prototypes
    void initD3D(HWND hWnd);    // sets up and initializes Direct3D
    void render_frame(void);    // renders a single frame
    void cleanD3D(void);    // closes Direct3D and releases memory
    void init_graphics(void);    // 3D declarations
    
    struct CUSTOMVERTEX {FLOAT X, Y, Z; DWORD COLOR;};
    #define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)
    
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    
    
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
        HWND hWnd;
        WNDCLASSEX wc;
    
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
    
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.lpszClassName = "WindowClass";
    
        RegisterClassEx(&wc);
    
        hWnd = CreateWindowEx(NULL, "WindowClass", "Our Direct3D Program",
                              WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                              NULL, NULL, hInstance, NULL);
    
        ShowWindow(hWnd, nCmdShow);
    
        // set up and initialize Direct3D
        initD3D(hWnd);
    
        // enter the main loop:
    
        MSG msg;
    
        while(TRUE)
        {
            while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
    
            if(msg.message == WM_QUIT)
                break;
    
            render_frame();
        }
    
        // clean up DirectX and COM
        cleanD3D();
    
        return msg.wParam;
    }
    
    
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
            case WM_DESTROY:
                {
                    PostQuitMessage(0);
                    return 0;
                } break;
        }
    
        return DefWindowProc (hWnd, message, wParam, lParam);
    }
    
    
    // this function initializes and prepares Direct3D for use
    void initD3D(HWND hWnd)
    {
        d3d = Direct3DCreate9(D3D_SDK_VERSION);
    
        D3DPRESENT_PARAMETERS d3dpp;
    
        ZeroMemory(&d3dpp, sizeof(d3dpp));
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.hDeviceWindow = hWnd;
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
        d3dpp.BackBufferWidth = SCREEN_WIDTH;
        d3dpp.BackBufferHeight = SCREEN_HEIGHT;
    
        // create a device class using this information and the info from the d3dpp stuct
        d3d->CreateDevice(D3DADAPTER_DEFAULT,
                          D3DDEVTYPE_HAL,
                          hWnd,
                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                          &d3dpp,
                          &d3ddev);
    
        init_graphics();    // call the function to initialize the triangle
    
        d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);    // turn off the 3D lighting
    }
    
    
    // this is the function used to render a single frame
    void render_frame(void)
    {
        d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    
        d3ddev->BeginScene();
    
        // select which vertex format we are using
        d3ddev->SetFVF(CUSTOMFVF);
    
        // SET UP THE PIPELINE
    
        D3DXMATRIX matRotateY;    // a matrix to store the rotation information
    
        static float index = 0.0f; index+=0.05f;    // an ever-increasing float value
    
        // build a matrix to rotate the model based on the increasing float value
        D3DXMatrixRotationY(&matRotateY, index);
    
        // tell Direct3D about our matrix
        d3ddev->SetTransform(D3DTS_WORLD, &matRotateY);
    
        D3DXMATRIX matView;    // the view transform matrix
    
        D3DXMatrixLookAtLH(&matView,
                           &D3DXVECTOR3 (0.0f, 0.0f, 10.0f),    // the camera position
                           &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position
                           &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction
    
        d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView
    
        D3DXMATRIX matProjection;     // the projection transform matrix
    
        D3DXMatrixPerspectiveFovLH(&matProjection,
                                   D3DXToRadian(45),    // the horizontal field of view
                                   (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
                                   1.0f,    // the near view-plane
                                   100.0f);    // the far view-plane
    
        d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection
    
        // select the vertex buffer to display
        d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
    
        // copy the vertex buffer to the back buffer
        d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
    
        d3ddev->EndScene();
    
        d3ddev->Present(NULL, NULL, NULL, NULL);
    }
    
    
    // this is the function that cleans up Direct3D and COM
    void cleanD3D(void)
    {
        v_buffer->Release();    // close and release the vertex buffer
        d3ddev->Release();    // close and release the 3D device
        d3d->Release();    // close and release Direct3D
    }
    
    
    // this is the function that puts the 3D models into video RAM
    void init_graphics(void)
    {
        // create the vertices using the CUSTOMVERTEX struct
        CUSTOMVERTEX vertices[] =
        {
            { 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), },
            { 0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), },
            { -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },
        };
    
        // create a vertex buffer interface called v_buffer
        d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
                                   0,
                                   CUSTOMFVF,
                                   D3DPOOL_MANAGED,
                                   &v_buffer,
                                   NULL);
    
        VOID* pVoid;    // a void pointer
    
        // lock v_buffer and load the vertices into it
        v_buffer->Lock(0, 0, (void**)&pVoid, 0);
        memcpy(pVoid, vertices, sizeof(vertices));
        v_buffer->Unlock();
    }
    The pragmas were suggested on another site I found while googling a solution. As you might guess, they didn't help, hence the comment out.

  5. #20
    Registered User
    Join Date
    May 2010
    Posts
    28
    neither d3dx9.lib nor d3dx9d.lib can be found

  6. #21
    Registered User
    Join Date
    May 2010
    Posts
    28
    I changed the order of those files you mentioned. Now it only tells me it can't find dxguid.lib. It stops at whatever the first file is.

  7. #22
    Registered User
    Join Date
    May 2010
    Posts
    28
    It did find d3d9.lib

    I did a search for both files. The difference is that this file is in
    C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib
    while d3dx9.lib is not. Apparently this is the directory it wants the includes to be in. I'm going to copy that file here and see what happens.

  8. #23
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    Don't copy the file... Then you just end up with junk everywhere. Just add the file with complete path, or add the folder to the solution so it knows to look there.

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    28
    SUCCESS

    I moved both files into that directory and it worked without errors. Now hopefully I won't have to pester you guys for a while.

  10. #25
    Registered User
    Join Date
    May 2010
    Posts
    28
    Sry, syz, I did it before I saw your post. Should I take them out?

  11. #26
    Registered User
    Join Date
    May 2010
    Posts
    28
    Add the complete path to linker->additional dependencies?

    Where in the solution would I add the folder?

  12. #27
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    I would remove any files you copied because they should not be in those folders. That is not the proper method.

    Try adding the paths to where those files are originally located in Linker->General->Additional Library Dependencies

  13. #28
    Registered User
    Join Date
    May 2010
    Posts
    28
    I don't see "additional library dependencies"

    I do see "additional library directories" is this what you meant?

    I put a directory where both files can be found:

    C:\Program Files\Microsoft DirectX SDK (June 2010)\Lib\x86

    here are my errors

    1>------ Build started: Project: autodidac_dx_2, Configuration: Debug Win32 ------
    1> LINK : C:\Documents and Settings\Rian Saville\My Documents\Visual Studio 2010\Projects\autodidac_dx_2\Debug\autodidac_dx_2. exe not found or not built by the last incremental link; performing full link
    1>prog.obj : error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "void __cdecl initD3D(struct HWND__ *)" (?initD3D@@YAXPAUHWND__@@@Z)
    1>prog.obj : error LNK2019: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
    1>prog.obj : error LNK2019: unresolved external symbol _D3DXMatrixLookAtLH@16 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
    1>prog.obj : error LNK2019: unresolved external symbol _D3DXMatrixRotationY@8 referenced in function "void __cdecl render_frame(void)" (?render_frame@@YAXXZ)
    1>C:\Documents and Settings\Rian Saville\My Documents\Visual Studio 2010\Projects\autodidac_dx_2\Debug\autodidac_dx_2. exe : fatal error LNK1120: 4 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    Are you sure I can't just copy them into the standard directory?

  14. #29
    Registered User
    Join Date
    Mar 2010
    Posts
    109
    Yes, I meant "Additional Library Directories." I was reading your comment while typing and messed up.

    You can do it however you want, but that is not the right way to do things.

    Do you still have the files listed inside Linker->Input->Additional Dependencies? You need them there also.

  15. #30
    Registered User
    Join Date
    May 2010
    Posts
    28
    No, I took them out thinking they'd be redundant but I'll go ahead and add them and see what happens.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help explaining test questions
    By Sentral in forum General Discussions
    Replies: 26
    Last Post: 11-09-2009, 11:10 PM
  2. DirectX - Starting Guide?
    By Zeusbwr in forum Game Programming
    Replies: 13
    Last Post: 11-25-2004, 12:49 AM
  3. DirectX 9 SDK
    By Polymorphic OOP in forum Windows Programming
    Replies: 4
    Last Post: 12-21-2002, 01:55 AM
  4. DirectX SDK and ActiveX SDK
    By moemen ahmed in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-30-2002, 04:16 AM
  5. Working Code Samples Wanted
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 10:05 PM