• 0

[C++][MSVC] Cannot resolve this Linker error LNK2019, DirectX related


Question

Okay guys and gals, I am absolutely 100% stumped on this one. I genuinely cannot seem to resolve this one. I've been trying for 5 days, experimenting, googling, all to no avail. I usually like to solve my own coding problems and try for as long as I can to resolve it, but this time I need some outside advice!

Basically, I'm using DirectX for my input. I have a CInput class using dinput.h to grab keyboard inputs. My compiler is MSVC++ 2010.

CInput.h


// input.h: interface for the Cinput class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_INPUT_H__9F947E83_2A3B_4B63_8675_83B41506943E__INCLUDED_)
#define AFX_INPUT_H__9F947E83_2A3B_4B63_8675_83B41506943E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <windows.h>
#define DIRECTINPUT_VERSION 0x0700
#include <dinput.h>

class CInput
{
private:
static CInput * _instance;
protected:
CInput(void);
public:
static CInput * Instance();
virtual ~CInput();
void GetInput();
bool GetIfKeyDown(int whichkey); //true as long as key still down
bool GetIfKeyDownEvent(int whichkey); //occurs only when key first pressed
};
#endif // !defined(AFX_INPUT_H__9F947E83_2A3B_4B63_8675_83B41506943E__INCLUDED_)
[/CODE]

CInput.cpp

[CODE]
// input.cpp: implementation of the Cinput class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Input.h"
#include <windows.h>
#include <OBJBASE.H>

extern HWND g_hWnd;
extern HINSTANCE hInst;
LPDIRECTINPUT lpdi; //pointer to direct input object
LPDIRECTINPUTDEVICE lpdikey; //the keyboard device
//storage for keyboard state
UCHAR keystate[256];
UCHAR oldkeystate[256];
bool keydown[256];
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CInput::CInput()
{

if (DirectInputCreateA(hInst, DIRECTINPUT_VERSION, &lpdi, NULL)!=DI_OK)
{
// DirectInput not available; take appropriate action
}

//create keyboard device
if(lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
{
//error
}
//set cooperation level
if(lpdikey->SetCooperativeLevel(g_hWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)!=DI_OK)
{
//error
}
//set data format
if(lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
{
//error
}
//acquire the keyboard device
if(lpdikey->Acquire()!=DI_OK)
{
//error
}

}
CInput::~CInput()
{
//unaquire keyboard
lpdikey->Unacquire();
lpdi->Release();
}
//this method refreshes the CInput class's data on which keys are currently down
//this data is stored in an array called keystate[ ]
void
CInput::GetInput()
{
//copy old keystate array
int i;
for (i=0;i<256;i++)
{
oldkeystate[i]=keystate[i];
}

if (lpdikey->GetDeviceState(256,keystate)!=DI_OK)
{
//error
}
//now check which keys are now down that weren't down last time
for (i=0;i<256;i++)
{
if ((keystate[i]>0)&&(oldkeystate[i]==0))
{
//key is now down and it wasn't before
keydown[i]=1;
}
else
{
keydown[i]=0;
}
}
}

//use this method with DirectX character constants
//which are defined in dinput.h such as DIK_SPACE
//relies on the GetInput( ) method being called first to
//update the data on which keys are currently down
//if this method doesn't seem to work then make sure you
//are calling GetInput( ) first!!!
bool
CInput::GetIfKeyDown(int whichkey)
{
if ((whichkey>256)|(whichkey<0)) return 0;
return (bool)(keystate[whichkey] & 0x80);
}
//method returns 1 or 0 depending on whether
//specified key has just been pressed
bool
CInput::GetIfKeyDownEvent(int whichkey)
{
if ((whichkey>256)|(whichkey<0)) return 0;
return (bool)(keydown[whichkey]);
}
CInput * CInput::Instance()
{
if (0==_instance)
{_instance=new CInput();
}
return _instance;
}
CInput * CInput::_instance=0;

[/CODE]

When I go to make a build, however, it compiles the code but throws up the linker error which I told you about. Here's my output from building:

[CODE]
1> Generating Code...
1>Input.obj : error LNK2019: unresolved external symbol _DirectInputCreateA@16 referenced in function "protected: __thiscall CInput::CInput(void)" (??0CInput@@IAE@XZ)
1>D:\Developer\ttSideScrollerWin32 - 2011 version\Debug\ttSideScrollerWin32.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
[/CODE]

From what I've read, LNK2019 usually gets thrown when something isn't being included in your project or hasn't been defined. However, the CInput Constructor has definitely been defined in my header, with both CInput.h and CInput.cpp included in my project. DirectX SDK is definitely installed, my Linker Input in my Project Properties includes dxguid.lib, dinput.lib and dinput8.lib. My VC++ Directories for Input and Libraries explicitly include DirectX SDK's folders for Input and Libraries. I've gone through everything I can think of, but everything seems to be in place. I presume it's some sort of compiler issue of some kind, and one that's probably beyond my expertise. However, I'm open to any suggestions. I'm returning to programming after a fair few months of inactivity and so I'm a little rusty, which probably hasn't helped me solve this issue.

So, please Neowin, help me!!!

2 answers to this question

Recommended Posts

  • 0

So.... yeah. I'm the world's biggest school-boy-erroring jackass.

Turns out, one small little thing I did right at the very beginning, which was re-naming dinput8.lib to dinput.lib in the very ignorant assumption would fix things, I forgot I did after I explored other avenues. Turns out, my code is pretty old now and was relying on an old version of DirectX SDK which used dinput.lib - which any DX programmer knows is pretty different to dinput8.lib (and both of which are pretty deprecated now anyway). A silly error made because I was rusty at coding. Installed a legacy version of DX which had dinput.lib, linked to that and it all compiles - thankfully. Of course, what I need to do now is re-write my Input class using a newer input library - anybody got any suggestions for input libraries in games? Just KB/M suppport is necessary but game controller support would be nice too!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Microsoft SharePoint gets Modern Page Templates to speed up page creation by Paul Hill SharePoint, Microsoft’s enterprise content management solution that allows organizations to set up internal pages and share documents, has just got a big update with the new Modern Page Templates. Microsoft said that it’s going to be rolling out the feature to customers globally between early July and early August. Organization members that want to set up pages on SharePoint using the new templates can do so from multiple entry points including the Site Home (the home of a Communication or Teams site), App Bar (the persistent navigation pane on the left of SharePoint), and the New Web Part (a webpart that displays and creates news posts directly on pages). By giving colleagues multiple access points to the new templates, there’s more chance they’ll be found and used. By including plenty of swanky templates, Microsoft is making it so you can spend less time designing pages, and more time filling them with content that really matters. If you want to create a new page using the templates, just go to New > Page and select a template “From Microsoft”. If you were making a news post, you would go to New > News post then you’d be presented with the new Template Gallery where you can select a custom template created by your colleagues under “Saved on this site”. While these new templates are coming to customers globally next month, Microsoft is already busy working on new features to make templates easier to discover and make them more useful. For example, it is building tenant-wide custom templates that can be published across sites for organization-wide use, and it’s working on Copilot templates that you can use when creating pages with Copilot. Neither of these features was given a release timeline. Customers won’t need to do anything to start using Modern Page Templates as they’ll be available automatically as it rolls out worldwide across tenants. For those who want to dive deeper, Microsoft will be publishing additional documentation and guidance about this feature soon.
    • Times are changing: https://arstechnica.com/gaming...ndows-11-ars-testing-finds/
    • Unless there is “bug” that all of a sudden sends your messages to Meta. Where have I heard this before?!
    • Maybe, just maybe... and it isn't you... there are some people who like the Windows 11 UI (for whatever reason) and want a better backend.
    • Gundams to arrive in Call of Duty: Mobile with new mech mode and unique third-person combat by Paul Hill Activision has announced that Call of Duty: Mobile will see the launch of Season 6 “Gundams Arrive” on July 2 at 5PM Pacific Time. This major collaboration between the world’s most popular FPS franchise and the Gundam franchise will introduce a new, limited-time mode called Gundam Team Deathmatch where 8 players will face off 4v4 and pilot Gundam-themed operators such as Ethan - Freedom Gundam, Reaper - Sazabi Gundam, Proton - v Gundamo, Deathscythe Gundam (EW). When playing in this game mode, players will notice a switch from the usual first-person view to the third-person perspective. The new game mode will also feature specific abilities and weapons that are unique to Gundam suits rather than player loadouts. The new Gundam Team Deathmatch mode will be played on a new map called interstellar space station, which has been designed for this mode. When playing, you’ll discover that the mech suits offer specialized mobility such as dodge, sprint, and vertical jets. In the post-match, players will be able to watch Gundam operator animations with unlockable rewards for viewing. You can unlock more animations by participating in Gundam Team Deathmatch, normal Multiplayer, and Battle Royale modes. There will also be Gundam-themed in-game events, such as Survival of the Fittest, which will give players free rewards like the new legendary weapon J358 — Fin Funnel v Gundam, Urban Tracker — Defense Force, Cyro Bomb — Haro (reskin), Emote — Haro Team, new camos, and more. Players will also be able to obtain a variety of items through Season 6 Battle Pass free and premium tiers, including sci-fi-themed Operators and Weapon Blueprints. Players on the free tier will get access to the bolt-action 3-Line Rifle based on a World War II design and is capable of inflicting high damage with high accuracy. Free tier players will also have the chance to earn other rewards such as Skins, Weapons Blueprints, Vault Coins, and more. Players looking to spend money can get the Premium Pass. These players will have a chance to get all of the content from Season 6 including tactical warriors like Silver — Chrome Dome Reskin, Misty — Science Pilot, Atlas — Dust Ranger, and The Marshal — Rock Hound; and Weapon Blueprints like the BP50 — Pathripper, Oden — Maevwat Technical, PDW-57 — Rocket Re-Entry, BY15 — Dark Moon, and the 3-Line Rifle — Geo Thermal Line, based on the new Season 6 weapon. There’s also Battle Pass Subscription which gives you additional monthly rewards along with a 10% boost to Player and Weapon XP, discount coupons, and limited discounts on 10x crate pulls. Activision also stated that Mythic Drops are returning to the Mythic store and that Battle Pass Vault is getting Season 9 — Zombies Are Back (2022) and Season 6 — Templar's Oath (2023).
  • Recent Achievements

    • Week One Done
      pcdoctorsnet earned a badge
      Week One Done
    • Rising Star
      Phillip0web went up a rank
      Rising Star
    • One Month Later
      Epaminombas earned a badge
      One Month Later
    • One Year In
      Bert Fershner earned a badge
      One Year In
    • Reacting Well
      ChrisOdinUK earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      539
    2. 2
      ATLien_0
      205
    3. 3
      +FloatingFatMan
      169
    4. 4
      Michael Scrip
      150
    5. 5
      Som
      126
  • Tell a friend

    Love Neowin? Tell a friend!