0


I'm following the DirectXTK GamePad tutorial on how to incorparate a GamePad into my application but I'm getting an errorLNK2019 when trying to create the GamePad.

So far I've:

  • included GamePad.h to my Controller header file

  • Added

    std::unique_ptr<DirectX::GamePad> mGamePad;
    

    in my Controller class

  • In Controller::Init() added

    mGamePad = std::make_unique<GamePad>();
    

And when I add that last line of code I get errors (loong ones):

DirectXTK.lib(GamePad.obj) : error LNK2019: unresolved external symbol __imp_RoGetActivationFactory referenced in function "long __cdecl ABI::Windows::Foundation::GetActivationFactory<struct ABI::Windows::Gaming::Input::IGamepadStatics>(struct HSTRING__ *,struct ABI::Windows::Gaming::Input::IGamepadStatics * *)" (??$GetActivationFactory@UIGamepadStatics@Input@Gaming@Windows@ABI@@@Foundation@Windows@ABI@@YAJPEAUHSTRING__@@PEAPEAUIGamepadStatics@Input@Gaming@12@@Z)
DirectXTK.lib(GamePad.obj) : error LNK2019: unresolved external symbol WindowsCreateStringReference referenced in function "private: void __cdecl Microsoft::WRL::Wrappers::HStringReference::CreateReference(wchar_t const *,unsigned int,unsigned int)" (?CreateReference@HStringReference@Wrappers@WRL@Microsoft@@AEAAXPEB_WII@Z)
fatal error LNK1120: 2 unresolved externals

In my application I already use the SpriteBatch without any problems so I'm guessing that I've done all the right things when I included DirectXTK to my solution.

I've also tried to create the GamePad using

mGamePad.reset( new GamePad() );

that I found in an older version of the tutorial.

Also.. The controller is inserted.. Any suggestions on what I'm doing wrong? Thank you!

SvinSimpe
  • 850
  • 1
  • 12
  • 28
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Apr 06 '16 at 01:31

2 Answers2

3

You have to link your project with RuntimeObject.lib

galop1n
  • 8,573
  • 22
  • 36
1

When DirectX Tool Kit's GamePad class is built for Windows 10 (i.e. _WIN32_WINNT=0x0A00) it uses the new Windows.Gaming.Input Windows Runtime classes instead of XINPUT.

If you are building for the Universal Windows Platform, then you already have Windows Runtime initialized, _WIN32_WINNT=0x0a00 and are likely linking against RuntimeObject.lib.

If you are building a Windows desktop (aka Win32 or "classic" app), then first make sure you really intend to be making it for Windows 10 only. There are a plethora of different vcxproj files for DirectX Tool Kit depending on exactly what platform you are targeting. If you do want to be targeting Windows 10 only with your Windows desktop app, that's totally cool but you'll need to explicitly initialize Windows Runtime for your app.

TL;DR: If you are making a Windows desktop app that requires Windows 10, then link with RuntimeObject.lib and add this to your app initialization (replacing CoInitialize or CoInitializeEx):

Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
if (FAILED(initialize))
    return 1;

If you are not making a Windows desktop app that requires Windows 10, and you are not making a Universal Windows Platform (UWP) app, then use a different version of the DirectX Tool Kit that's built for Windows 7 compatibility.

See this post

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81