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.
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.