2017-02-27 164 views
0

我想創建一個GPU渲染粒子系統,它使用這個輸入類來處理鼠標/鍵盤輸入。DX11 DirectInput8Create導致LNK2019錯誤

問題是這條線;

HRESULT result = DirectInput8Create(.....); 

導致LNK2019:無法解析的外部符號錯誤。我已經包含了必要的文件,所以我不確定爲什麼會發生這種情況。下面分別是Input.h和文件。

INPUT.H文件

#ifndef _INPUT_ 
#define _INPUT_ 

#include <stdafx.h> 
#include <dinput.h> 

class Input{ 
private: 
    IDirectInputDevice8* _DIKeyboard; 
    IDirectInputDevice8* _DIMouse; 

    LPDIRECTINPUT8   _directInput; 

    LONG     _mouseXabsolute, _mouseYabsolute, _mouseZabsolute; 
    LONG     _mouseXrelative, _mouseYrelative, _mouseZrelative; 
    BYTE     _keyboardState[256]; 
    BYTE     _leftMouseButton, _rightMouseButton; 

    int      _screenWidth, _screenHeight; 
    HWND     _hWnd; 

    POINT     _point; 
    RECT     _rect; 

public: 
    Input(); 
    ~Input(); 

    void unload(); 
    bool initializeInput(HINSTANCE hInstance, HWND hWnd, int screenWidth, int screenHeight); 

    void updateInput(); 

    BYTE* getKeyboardState(); 

    LONG getMouseXRelative(); 
    LONG getMouseYRelative(); 
    LONG getMouseZRelative(); 

    LONG getMouseXAbsolute(); 
    LONG getMouseYAbsolute(); 
    LONG getMouseZAbsolute(); 

    BYTE getLeftMouseClick(); 
    BYTE getRightMouseClick(); 
}; 

#endif 

INPUT.CPP文件

#include <stdafx.h> 
#include <Input.h> 
#define DIRECTINPUT_VERSION 0x0800 
#include <dinput.h> 

using namespace std; 

Input::Input() : _DIKeyboard(), _DIMouse(), _directInput(), _point(), _rect(){ 
    _mouseXabsolute = _mouseYabsolute = 0; 
    _mouseZabsolute = 1; 
    _mouseXrelative = _mouseXrelative = _mouseXrelative = 0; 
} 

Input::~Input(){ 
    unload(); 
} 

void Input::unload(){ 
    if (_DIKeyboard) _DIKeyboard->Release(); 
    if (_DIMouse) _DIMouse->Release(); 
    if (_directInput) _directInput->Release(); 
} 

bool Input::initializeInput(HINSTANCE hInstance, HWND hWnd, int screenWidth, int screenHeight){ 

    _screenWidth = screenWidth; 
    _screenHeight = screenHeight; 
    _hWnd = hWnd; 
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
    ///////////////////////////////////////////////Create direct input, keyboard and mouse devices/////////////////////////////////////////////////// 

    HRESULT result = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&_directInput, NULL); 

    if (FAILED(result)){ 
     MessageBox(0, L"Could not create direct input!", L"Error", MB_OK); 
     return false; 
    } 
... 
... 
... 
} 

我想感謝所有幫助來解決這個問題。

+0

這是一個鏈接錯誤讓你的.h和.cpp文件無關緊要。您只是忘了鏈接導入庫,dinput8.lib –

+1

請注意,如果您使用的是DirectX 11,則不需要使用古老的DirectInput。此外,在現代版本的Windows上不應該使用DirectInput進行鍵盤或鼠標輸入 - 它只是在Win32消息的基礎上實現的。請參閱[DirectX Tool Kit:現在帶有GamePads](https://blogs.msdn.microsoft.com/chuckw/2014/09/05/directx-tool-kit-now-with-gamepads/)和[DirectX Tool Kit:鍵盤和鼠標支持](https://blogs.msdn.microsoft.com/chuckw/2015/08/06/directx-tool-kit-keyboard-and-mouse-support/)。 –

回答