.NET Framework Developer Center > .NET Framework Forums > Common Language Runtime > COM, C++/CLI, C# and CoInitialize()/CoUninitialize()

Answered COM, C++/CLI, C# and CoInitialize()/CoUninitialize()

  • Thursday, March 18, 2010 11:11 AM
     
     
    Hi all,

    I'm working on a project which makes use of COM in unmanaged C++. That unmanaged C++ is then wrapped in a managed C++ class. Finally, this managed C++ class is then consumed in a C# application. I'd like the unmanaged C++ and the wrapper to became a simple .NET dll

    What is the best way to handle the call(s) to CoInitialize()/CoUninitialize() for the COM being used in the unmanaged C++?

    I have the following options:
    - Add a call to CoInitialize() in the constructor for the unmanaged C++ class and a call to CoUninitialize() in the destructor.
    - Calling that functions each time a create a thread from C# trough a PInvoke call or trough a managed C++ wrapper.

    I prefer the first method: do anyone see any issue with that?
    Is there an easier way to do this?

    Thanks

Answers

All Replies