简体   繁体   English

使用DirectX 11时出现未解决的链接错误

[英]unresolved link error when working with directx 11

I was attempting to create a class that instances my directx window I have an initialize method and a clean method that I have pushed into a .h and .cpp file and upon doing so I get these 2 errors: 我试图创建一个类来作为我的DirectX窗口的实例,我有一个initialize方法和一个clean方法,这些方法已推送到.h和.cpp文件中,执行此操作时出现以下两个错误:

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 错误58错误LNK2019:未解决的外部符号“公共:void __cdecl D3DWindow :: CleanD3D(void)”(?CleanD3D @ D3DWindow @@ QEAAXXZ)在函数WinMain C:\\ Users \\ thatguy \\ Documents \\ games \\ tutorial work \\ directx中引用11教程\\ Directx 11教程\\ main.obj DirectX 11教程

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 错误59错误LNK2019:未解决的外部符号“ public:void cdecl D3DWindow :: InitD3D(struct HWND *)”(?InitD3D @ D3DWindow @@ QEAAXPEAUHWND __ @@@ Z)在函数WinMain C:\\ Users \\ thatguy \\ Documents \\ game中引用开发人员\\教程工作\\ DirectX 11教程\\ DirectX 11教程\\ main.obj DirectX 11教程

main.cpp: main.cpp:

// include the basic windows header files and the Direct3D header files
#include <windows.h>
#include <windowsx.h>
#include "D3DWindow.h"

// 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.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 up and initialize Direct3D
    window.InitD3D(hWnd);

    // enter the 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 up DirectX and COM
    window.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);
}

D3DWindow.h: 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: D3DWindow.cpp:

#include "D3DWindow.h"
#include <windows.h>

// global declarations
IDXGISwapChain *swapchain;             // the pointer to the swap chain interface
ID3D11Device *dev;                     // the pointer to our Direct3D device interface
ID3D11DeviceContext *devcon;           // the pointer to our Direct3D device context

D3DWindow::D3DWindow(void)
{
}


D3DWindow::~D3DWindow(void)
{
}

// this function initializes and prepares Direct3D for use
void InitD3D(HWND hWnd)
{
    // create a struct to hold information about the swap chain
    DXGI_SWAP_CHAIN_DESC scd;

    // clear out the struct for use
    ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

    // fill the swap chain description struct
    scd.BufferCount = 1;                                    // one back buffer
    scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;     // use 32-bit color
    scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;      // how swap chain is to be used
    scd.OutputWindow = hWnd;                                // the window to be used
    scd.SampleDesc.Count = 4;                               // how many multisamples
    scd.Windowed = TRUE;                                    // windowed/full-screen mode

    // create a device, device context and swap chain using the information in the scd struct
    D3D11CreateDeviceAndSwapChain(NULL,
                                  D3D_DRIVER_TYPE_HARDWARE,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL,
                                  D3D11_SDK_VERSION,
                                  &scd,
                                  &swapchain,
                                  &dev,
                                  NULL,
                                  &devcon);
}


// this is the function that cleans up Direct3D and COM
void CleanD3D(void)
{
    // close and release all existing COM objects
    swapchain->Release();
    dev->Release();
    devcon->Release();
}

It is in all honesty probably something I overlooked but I'm not really sure why it wouldn't work when it works all under one file. 老实说,这可能是我忽略的事情,但我不确定为什么当所有文件都放在一个文件中时,为什么它不起作用。

Thanks for any and all help. 感谢您提供的所有帮助。

void InitD3D(HWND hWnd)

should be 应该

void D3DWindow::InitD3D(HWND hWnd)

same for CleanD3D. 与CleanD3D相同。

Incidentally there doesn't seem to be a lot of point to your D3DWindow class. 顺便说一句,您的D3DWindow类似乎没有很多意义。 Why did you decide to write InitD3D and CleanD3D as part of a class? 您为什么决定将InitD3D和CleanD3D编写为类的一部分? The way you have written the you could have just written them as global functions. 您编写的方式可能只是将它们编写为全局函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM