combase error (CoInitialize has not been called)

时光总嘲笑我的痴心妄想 提交于 2021-01-27 12:50:30

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/46917871/combase-error-coinitialize-has-not-been-called

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!