1

I am using the DirectXTK library for the gamepad class. I compiled the library with only this class inside it and it works.

If I would only add the source files to my project, without the library, the size would be ~50KB instead of ~500KB. However, I am receiving the following error:

CoInitialize has not been called

Any ideas on how to resolve this so my executable would be smaller in size?

Z0q
  • 1,689
  • 3
  • 28
  • 57
  • As it's not an answer, I'll put it as a comment: "size matters not". Not only for Yoda, but also for us developers. 50K or 500K? Nobody will care. – nvoigt Jan 20 '17 at 11:57

1 Answers1

3

Well, you could call CoInitialize yourself as the first thing in main.

int main()
{
    CoInitialize(NULL);

    // your code

    return 0;
}
nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • Hi, thank you. I did that, and the project compiles. However, the gamepad is not detected while the project with the library does detect it – Z0q Jan 20 '17 at 11:58
  • @Z0q The library probably does more than this initialization, just that the rest of it does not raise errors. Can you look at the source of the library and check? For example the call to `CoInitialize` must have occurred somewhere, if you can find the source, you might find what else is missing. – nvoigt Jan 20 '17 at 12:00
  • This function is not called in the source of the library. However, there is one note I found in one of the source files which says "// Note: Assumes application has already called CoInitializeEx". – Z0q Jan 20 '17 at 12:03
  • 1
    Remember to call CoUninitialize() to pair the each CoInitiallize. – Chen OT Jan 20 '17 at 13:01
  • This is addressed in the [wiki](https://github.com/Microsoft/DirectXTK/wiki/GamePad#windows). Use of ``Windows.Gaming.Input`` requires Windows Runtime to be initialized. The C/C++ Runtime will do this for a UWP, but classic desktop apps need to do this explicitly. If you are using the version of ``GamePad`` that works on older operating systems, COM is not needed for XINPUT although it is needed for WIC which is used by DirectXTK/DirectXTex for image loading. – Chuck Walbourn Jan 24 '17 at 07:11
  • Note that ``Windows.Gaming.Input`` needs the Windows Runtime initialized which also initializes COM--it is 'modern COM' after all. The easiest solution is to use [WRL](https://msdn.microsoft.com/en-us/library/hh438466.aspx) instead of calling ``CoInitialize(Ex)``: ``Microsoft::WRL::Wrappers::RoInitializeWrapper initialize(RO_INIT_MULTITHREADED); if (FAILED(initialize)) // error`` – Chuck Walbourn Jan 24 '17 at 07:17