c++ - unresolved link error when working with directx 11 -
i attempting create class instances directx window have initialize method , clean method have pushed .h , .cpp file , upon doing these 2 errors:
error 58 error lnk2019: unresolved external symbol "public: void __cdecl d3dwindow::cleand3d(void)" (?cleand3d@d3dwindow@@qeaaxxz) referenced in function winmain c:\users\thatguy\documents\game dev\tutorial work\directx 11 tutorial\directx 11 tutorial\main.obj directx 11 tutorial
error 59 error lnk2019: unresolved external symbol "public: void cdecl d3dwindow::initd3d(struct hwnd *)" (?initd3d@d3dwindow@@qeaaxpeauhwnd__@@@z) referenced in function winmain c:\users\thatguy\documents\game dev\tutorial work\directx 11 tutorial\directx 11 tutorial\main.obj directx 11 tutorial
main.cpp:
// include basic windows header files , direct3d header files #include <windows.h> #include <windowsx.h> #include "d3dwindow.h" // windowproc function prototype lresult callback windowproc(hwnd hwnd, uint message, wparam wparam, lparam lparam); // entry point 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.hbrbackground = (hbrush)color_window; wc.lpszclassname = "windowclass"; registerclassex(&wc); rect wr = {0, 0, 800, 600}; adjustwindowrect(&wr, ws_overlappedwindow, false); hwnd = createwindowex(null, "windowclass", "our first direct3d program", ws_overlappedwindow, 300, 300, wr.right - wr.left, wr.bottom - wr.top, null, null, hinstance, null); showwindow(hwnd, ncmdshow); d3dwindow window; // set , initialize direct3d window.initd3d(hwnd); // enter main loop: msg msg; while(true) { if(peekmessage(&msg, null, 0, 0, pm_remove)) { translatemessage(&msg); dispatchmessage(&msg); if(msg.message == wm_quit) break; } else { // run game code here // ... // ... } } // clean directx , com window.cleand3d(); return msg.wparam; } // main message handler 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); }
d3dwindow.h:
#include <windows.h> #include <d3d11.h> #include <d3dx11.h> #include <d3dx10.h> #pragma once class d3dwindow { public: d3dwindow(void); ~d3dwindow(void); void cleand3d(); void initd3d(hwnd hwnd); };
d3dwindow.cpp:
#include "d3dwindow.h" #include <windows.h> // global declarations idxgiswapchain *swapchain; // pointer swap chain interface id3d11device *dev; // pointer our direct3d device interface id3d11devicecontext *devcon; // pointer our direct3d device context d3dwindow::d3dwindow(void) { } d3dwindow::~d3dwindow(void) { } // function initializes , prepares direct3d use void initd3d(hwnd hwnd) { // create struct hold information swap chain dxgi_swap_chain_desc scd; // clear out struct use zeromemory(&scd, sizeof(dxgi_swap_chain_desc)); // fill swap chain description struct scd.buffercount = 1; // 1 buffer scd.bufferdesc.format = dxgi_format_r8g8b8a8_unorm; // use 32-bit color scd.bufferusage = dxgi_usage_render_target_output; // how swap chain used scd.outputwindow = hwnd; // window used scd.sampledesc.count = 4; // how many multisamples scd.windowed = true; // windowed/full-screen mode // create device, device context , swap chain using information in scd struct d3d11createdeviceandswapchain(null, d3d_driver_type_hardware, null, null, null, null, d3d11_sdk_version, &scd, &swapchain, &dev, null, &devcon); } // function cleans direct3d , com void cleand3d(void) { // close , release existing com objects swapchain->release(); dev->release(); devcon->release(); }
it in honesty overlooked i'm not sure why wouldn't work when works under 1 file.
thanks , help.
void initd3d(hwnd hwnd)
should be
void d3dwindow::initd3d(hwnd hwnd)
same cleand3d.
incidentally there doesn't seem lot of point d3dwindow class. why did decide write initd3d , cleand3d part of class? way have written have written them global functions.
Comments
Post a Comment