4

onecore\com\combase\objact\objact.cxx(812)\combase.dll!00007FF8BD322169: (caller: 00007FF8BD320F78) ReturnHr(1) tid(b54) 800401F0 CoInitialize has not been called.

I'm using Visual Studio 2015 and have started receiving the following error message. I'm not trying to write dll's or using COM objects or whatever. It's just a simple OpenGL program. I have no idea where this error message has come from. How do I get rid of it?

StinkyCoo
  • 83
  • 1
  • 5
  • Please give us code. Check the program in the debugger. Give us a chance to help in giving us more information! – xMRi Oct 24 '17 at 18:58
  • Code wouldn't help as I haven't changed anything since it last worked. Plus the code is thousands of lines in many files. What code would I post? – StinkyCoo Oct 25 '17 at 18:23
  • In such a case you have to tell us more about the code structure. See answer of Daniel Sęk. It shouldn't be very surprising if your question gets closed if you don't write more. – xMRi Oct 26 '17 at 05:52

2 Answers2

5

You are using COM implicitly. Without code, we don't know exacly. It could be something from shell api, common file dialog, joystick handling etc.

You need to put CoInitialize( 0 ); at the beginning of some main function (or WinMain or wWinMain), and CoUninitialize(); at function end. There is also CoInitializeEx if you need to use specific concurrency model.

CoInitialize description

Daniel Sęk
  • 2,504
  • 1
  • 8
  • 17
  • Thanks but I can't post the code as it wouldn't help much. It's thousands and thousands of lines of code in many separate modules. Posting code wouldn't help. I literally haven't changed anything with the code for months. I just came back to it recently and have this error. It doesn't make sense. I think it may have been since I updated the VS2015 software. I do use DirectX for reading the XBox controller. Maybe it is that, – StinkyCoo Oct 25 '17 at 18:20
  • Thanks this solution fixed the problem. – StinkyCoo Oct 26 '17 at 07:24
  • What is the consequence of this warning? Why should the warning be suppressed, other than the fact that it's annoying? – Cuadue Dec 09 '20 at 20:43
  • COM using components could fail without properly set threading model. It seems that some components just correct missing `CoInitialize` or `CoInitializeEx` by calling it themselves. Sometimes you can get conflicting models so it is better to select it explicitly at application start. – Daniel Sęk Dec 10 '20 at 15:34
1

My program calls CoInitialize(NULL) in WinMain, but I still see this error when loading some DLLs (after it's run.) However, I get this same error when trying to enumerate sound cards in the system. The solution is to use CoInitializeEx(NULL, COINIT_MULTITHREADED), which will make sure COM calls are allowed from any thread.

Jon Watte
  • 6,579
  • 4
  • 53
  • 63
  • What library is this defined in? I get an unresolved external when I try to call this. – Shavais Sep 17 '22 at 16:18
  • 1
    It is defined in Ole32.lib, and you include Objbase.h. More docs on what used to be MSDN and is now "learn.microsoft": https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-coinitializeex – Jon Watte Sep 28 '22 at 18:20