Jump to content
  • Advertisement
Sign in to follow this  
NikiTo

Can't CoInitializeEx() inside DLL

This topic is 394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My main project is a C# console application and it generates an exe. C# calls functions exported from a dll written in C++. I do nothing weird nowhere inside the code. The DllMain inside the dll is empty. When I try to call CoInitializeEx(null, COINIT_APARTMENTTHREADED) i get error: RPC_E_CHANGED_MODE.

I never touch or use threads declarations, neither COM related stuff nowhere in the code. Who is declaring the model as MULTITHREADED and how should I deal with the problem? Should I somehow initialize the dll as single threaded? Do I need CoInitializeEx() at all? I am afraid to simply delete it to not break something on my computer.

Share this post


Link to post
Share on other sites
Advertisement
I'm guessing that the C# thread has already called CoInitializeEx itself. I believe this is what the [STAThread] and [MTAThread] attributes do on the default Program.Main function that a new project template has.

If your C# entry point doesn't have [STAThread] on it, try adding it.

Share this post


Link to post
Share on other sites

Thank you for the answer, @Nypyren! You suggested that the template is setting the threading for me. I was afraid to add STAThread and mess something, that's why I first tried what was easier- I just out-commented the CoInitializeEx in the constructor of the class that use COM and the CoUnitialize in the destructor and it is working without a problem. I hope it will not give me headaches in the future. COM seems enough tricky for me as to add to it the complexity of threading.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!