1

I'm trying to create a GPU rendered particle system, and it uses this input class to handle mouse/keyboard input.

The issue is the line;

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

causes a LNK2019: Unresolved External Symbol error. I've included the necessary files, so I'm not sure why this is happening. Below is the Input.h and Input.cpp files respectively.

INPUT.H file

#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 File

#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;
    }
...
...
...
}

I'd appreciate any help to solve this issue.

NeoKuro
  • 457
  • 1
  • 5
  • 21
  • It is a linker error so your .h and .cpp files are irrelevant. You simply forgot to link the import library, dinput8.lib – Hans Passant Feb 27 '17 at 20:39
  • 1
    Note that if you are using DirectX 11, there's no need to use ancient DirectInput. Furthermore, you shouldn't use DirectInput for keyboard or mouse input on modern versions of Windows--it's just implemented on top of Win32 messages. See [DirectX Tool Kit: Now with GamePads](https://blogs.msdn.microsoft.com/chuckw/2014/09/05/directx-tool-kit-now-with-gamepads/) and [DirectX Tool Kit: Keyboard and Mouse support](https://blogs.msdn.microsoft.com/chuckw/2015/08/06/directx-tool-kit-keyboard-and-mouse-support/). – Chuck Walbourn Feb 27 '17 at 21:15

1 Answers1

2

You should link to dinput8.lib static library:

#pragma comment(lib, "dinput8")

Besides, you should consider using Raw input APIs instead of DirectInput: https://msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx

Asesh
  • 3,186
  • 2
  • 21
  • 31