• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Adam Turner

DX11
D3D11CreateDeviceAndSwapChain - Cannot work out why the link errors occur

2 posts in this topic

Introduction

Would like help with the D3D11CreateDeviceAndSwapChain when i implement it i receive LNK2019 and LNK1120:3. I would like help to resolve these issues and also perhaps help understanding the why as well.

I am trying to set up the window i recently developed to be linked through Dirct3D and the graphic(s) card.

 

 

Main Section Title
Explaining the Concept

The problem im facing as mentioned is link errors, im unsure why i am receiving the errors and the code looks just fine to me, i haven't programmed for nearly 4 years and i am very out of practice below i will link the code.

The code section that is causing the problem is:

D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL,
        NULL, NULL, D3D11_SDK_VERSION, &scd,
        &swapchain, &d3d_device, NULL, &dev_context);

This is what is causing the problem in the program. I will show the full code in both the cpp and hpp file to help understand.

 

Using the Code

I have created a class for Direct3D to keep things easier for me while programming. I am unsure if this may have anything to do with the problem here.

WindowInit.hpp

#ifndef D3DAPP_HPP
#define D3DAPP_HPP

/////////////////////////////////////////////////////////////////////////////////////////////////// WINDOW STUFF ////////////////////////////////////////////////////////////////////////////////////////////////////////

/* INCLUDE FILES GO HERE */

// include the basic windows header file
#include <windows.h>
#include <windowsx.h>


/* DEFINITIONS GO HERE */

// Long pointers to strings, constances for window class and title
const wchar_t lpszClassName[] = L"Window WindowClassEx"; // window class name
const wchar_t lpszTitleName[] = L"Window - 64bit 0.00"; // window title

// Define screen constant(s)
#define WINDOW_X        CW_USEDEFAULT    // x start draw coordinate
#define WINDOW_Y        CW_USEDEFAULT    // y start draw coordinate

#define WINDOW_WIDTH    800    // screen width
#define WINDOW_HEIGHT    600 // screen height

// Define macro message box(s)
//#define ERROR(g_msg)(MessageBoxW(g_hWnd, g_msg, L"ERROR", MB_ICONERROR)); // error handling message box
#define SUCCESSFUL(g_msg)(MessageBoxW(g_hWnd, g_msg, L"SUCCESS", NULL)); // success handling message box

#define MSG(g_msg)(MessageBoxW(g_hWnd,g_msg, L"Message", MB_ICONINFORMATION)); // error handling message box



/* GLOBAL VARIABLES GO HERE */

// the handle for the window, filled by a function
HWND g_hWnd;
// this struct holds information for the window class
WNDCLASSEX g_wc;
// this struct holds Windows event messages
MSG g_msg;




/* GLOBAL FUNCTIONS GO HERE */

// window initialising functions here
bool f_WindowInit(HINSTANCE hInstance, HWND hWnd, int showWindow); // initialise the main window with the window class structure and the create window function

// application run time 
int f_EngineRun();

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
    UINT message,
    WPARAM wParam,
    LPARAM lParam);

/////////////////////////////////////////////////////////////////////////////////////////////////// WINDOW STUFF ////////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////// DIRECT3D STUFF ///////////////////////////////////////////////////////////////////////////////////////////////////////

/* INCLUDE FILES GO HERE */

// include directx header file
// #include <direct.h>
#include <d3d11.h>
#include <D3DX11.h>

/* GLOBAL CLASSES GO HERE */
class cD3D
{
    // call the constructor and initialise the deconstructor
public:
    cD3D();    // constructor
    ~cD3D();    // deconstructor

    // Private member data type(s)
private:
    IDXGISwapChain *swapchain;    // the pointer to the swap chain interface
    ID3D11Device *d3d_device;    // the pointer to our Direct3D device interface
    ID3D11DeviceContext *dev_context;    // the pointer to our Direct3D device context

    // Public function(s)
public:
    bool f_D3DInit(HWND hWnd);    // initalise direct3d with the window and get a handle to the gfx card
    bool f_D3DCleanUp(void);    // clean up direct3d and release all memory back to the system
};

#endif // D3DAPP_HPP

Main.cpp

/* INCLUDE FILES GO HERE */

#include <WindowInit.hpp> // include required definitions


////////////////////////////////////////////////////////////////////////////////////////////// WINDOW EXECUTION AND EVENTS //////////////////////////////////////////////////////////////////////////////////////////////


/* WINDOW MAIN */

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    // Initialise Window
    if (!f_WindowInit(hInstance, g_hWnd, nCmdShow))
    {
        MessageBox(g_hWnd, L"ERROR - f_D3DWindowInit() failed to initialise!", NULL, NULL);
        PostQuitMessage(0);
    };    // set up the window

    cD3D    d3d;
    d3d.f_D3DInit(g_hWnd);

    // enter the main loop:
    return f_EngineRun();    // enter the main window message loop
}


// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // sort through and find what code to run for the message given
    switch (message)
    {
    case WM_KEYDOWN:
    {
        if (wParam == VK_ESCAPE)
        { // close the application entirely
            PostQuitMessage(0);
            return 0;
        }

        if (wParam == VK_F1)
        { // close the application entirely
            // PostQuitMessage(0);
            MSG(L"Hello im Adam's Window")
                return DefWindowProc(hWnd, message, wParam, lParam);
        }

    }
        // this message is read when the window is closed
    case WM_DESTROY:
    {
        // close the application entirely
        PostQuitMessage(0);
        return 0;
    } break;
    }

    // Handle any messages the switch statement didn't
    return DefWindowProc(hWnd, message, wParam, lParam);
}


////////////////////////////////////////////////////////////////////////////////////////////// WINDOW EXECUTION AND EVENTS //////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////////////////////// WINDOW INITALISATION STUFF //////////////////////////////////////////////////////////////////////////////////////////////


/* WINDOW INITIALISATION GOES HERE */

// Window initialisation 
bool f_WindowInit(HINSTANCE hInstance, HWND hWnd, int showWindow)
{
    // clear out the window class for use
    ZeroMemory(&g_wc, sizeof(WNDCLASSEX));

    // fill in the struct with the needed information
    g_wc.cbSize = sizeof(WNDCLASSEX);
    g_wc.style = CS_HREDRAW | CS_VREDRAW;
    g_wc.lpfnWndProc = WindowProc;
    g_wc.hInstance = hInstance;
    g_wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    g_wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    g_wc.lpszClassName = lpszClassName;

    // register the window class
    if (!RegisterClassEx(&g_wc))
    {
        ERROR(L"WindowClassEx failed to register!");
        PostQuitMessage(0);
    };

    // create the window and use the result as the handle
    g_hWnd = CreateWindowEx(NULL,

        // class, title and style
        lpszClassName, // name of the window class
        lpszTitleName, // title of the window
        WS_OVERLAPPEDWINDOW, // window style

        // window draw coordinate and size of window in pixels
        WINDOW_X, // x-position of the window
        WINDOW_Y, // y-position of the window
        WINDOW_WIDTH, // width of the window
        WINDOW_HEIGHT, // height of the window

        // state we have no parent window, not using menu's, attatch to window instance, multiple window's = false
        NULL, // we have no parent window, NULL
        NULL, // we aren't using menus, NULL
        hInstance, // application handle
        NULL); // used with multiple windows, NULL

    // test the value returned by CreateWindowEx stored in g_hWnd
    if (g_hWnd == 0)
    {
        ERROR(L"CreateWindowEx failed to be created!");
        PostQuitMessage(0);
    }

    // display the window on the screen
    ShowWindow(g_hWnd, showWindow);

    return true;
}


// Main loop function
int f_EngineRun()
{
    while (GetMessage(&g_msg, NULL, 0, 0))
    {
        // translate keystroke messages into the right format
        TranslateMessage(&g_msg);

        // send the message to the WindowProc function
        DispatchMessage(&g_msg);
    }

    // return this part of the WM_QUIT message to Windows
    return g_msg.wParam;
}

/////////////////////////////////////////////////////////////////////////////////////////////// WINDOW INITALISATION STUFF //////////////////////////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////////////////////// DIRECT3D INITALISATION STUFF /////////////////////////////////////////////////////////////////////////////////////////////
bool cD3D::f_D3DInit(HWND hWnd)
{
    DXGI_SWAP_CHAIN_DESC    scd;

    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    scd.BufferCount = 1;
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    scd.OutputWindow = hWnd;
    scd.SampleDesc.Count = 4;
    scd.Windowed = TRUE;


    D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL,
        NULL, NULL, D3D11_SDK_VERSION, &scd,
        &swapchain, &d3d_device, NULL, &dev_context);

    return true;
}

bool cD3D::f_D3DCleanUp(void)
{
    swapchain();
    3d_device->Release();
    dev_context->Release();

    return true;
}

Again when i add the

D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL,
        NULL, NULL, D3D11_SDK_VERSION, &scd,
        &swapchain, &d3d_device, NULL, &dev_context);

I reveive the link error:

Error 31 error LNK2019: unresolved external symbol _D3D11CreateDeviceAndSwapChain@48 referenced in function "public: bool __thiscall cD3D::f_D3DInit(struct HWND__ *)" (?f_D3DInit@cD3D@@QAE_NPAUHWND__@@@Z) D:\Development\C++ Project(s)\Testing Area\Playing around with code\D3D_Engine__0_00\D3D_Engine__0_00\Main.obj D3D_Engine__0_00

followed by

Error 32 error LNK2019: unresolved external symbol "public: __thiscall cD3D::cD3D(void)" (??0cD3D@@QAE@XZ) referenced in function _WinMain@16 D:\Development\C++ Project(s)\Testing Area\Playing around with code\D3D_Engine__0_00\D3D_Engine__0_00\Main.obj D3D_Engine__0_00

Error 33 error LNK2019: unresolved external symbol "public: __thiscall cD3D::~cD3D(void)" (??1cD3D@@QAE@XZ) referenced in function _WinMain@16 D:\Development\C++ Project(s)\Testing Area\Playing around with code\D3D_Engine__0_00\D3D_Engine__0_00\Main.obj D3D_Engine__0_00

Error 34 error LNK1120: 3 unresolved externals D:\Development\C++ Project(s)\Testing Area\Playing around with code\D3D_Engine__0_00\Debug\D3D_Engine__0_00.exe 1 1 D3D_Engine__0_00

 

 

 

Conclusion

 

I have tried removing the class and nothing changes no matter how i get the result i desire from the program, please help.

0

Share this post


Link to post
Share on other sites

unresolved external symbol _D3D11CreateDeviceAndSwapChain

You didn’t link to D3D11.lib. Add it to your project linker includes or use #pragma comment( lib, "d3d11.lib" ).

unresolved external symbol "public: __thiscall cD3D::cD3D(void)

You never defined the constructor or destructor, assuming your posted code is complete in this regard.


L. Spiro
2

Share this post


Link to post
Share on other sites

Thank you for taking the time to review the problem and you are right, my linker was set to only look at the 64bit lib folder and not the x86 folder  of the SDK. So it couldn't find the "d3d11.lib" file.

 

And unfortunately the code is only half complete.

 

Thanks again tho i can now complete my code.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
    • By MarcusAseth
      bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }  
      As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
      I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
      How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
      Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device) 
    • By ProfL
      Can anyone recommend a wrapper for Direct3D 11 that is similarly simple to use as SFML? I don't need all the image formats etc. BUT I want a simple way to open a window, allocate a texture, buffer, shader.
    • By lucky6969b
      Q1:
      Since there is no more fixed pipeline rendering in DX11, for every part of rendering in DX11, do I need to create a brand-new vertex shader and pixel shader... or at least I have to find one relevant online. If you work on skinned meshes and other effects originally worked in DX9 fixed pipeline, do I have to rework everything by now?
       
      Q2:
      For assimp, if it originally was designed for DX9, like it is coupled to a DX9 device for creating meshes and materials etc. Do I have to add in the DX11 device in the assimp, or can I just leave the assimp to remain in DX9 and after the meshes are loaded, I just convert the vertex buffers and index buffers into DX11 buffers?
      Thanks
      Jack
    • By MarcusAseth
      This header is mentioned in the book I'm reading but there is no documentation on msdn... Is it like an... outdated and abandoned header?
      If so, what's the current default/recomended library for handling errors with directX?
  • Popular Now