CComPtr CoCreateInstance returns 0x80070582 (Class already exists.)

Posted by Trevor Balcom on Stack Overflow See other posts from Stack Overflow or by Trevor Balcom
Published on 2010-05-18T16:04:57Z Indexed on 2010/05/18 17:40 UTC
Read the original article Hit count: 428

Filed under:
|
|
|

I have a StartComObjects function called when the user presses the Login button and a StopComObjects function called when the user presses the Cancel button. The StartComObjects function uses CComPtr.CoCreateInstance to create the COM object and sets up some connection points using AfxConnectionAdvise. When the user presses the Cancel button the connection points are disconnected using AfxConnectionUnadvise and the COM object is stopped before calling Release on the CComPtr.

When I press the login button a second time the CComPtr.CoCreateInstance returns 0x80070582 (Class already exists). This prevents the COM object from being created on the second call to StartComObjects. I am not sure why this isn't working. Shouldn't CComPtr::Release free the COM object and allow me to create a new one after the old one was stopped? Is there any way to get around this?

© Stack Overflow or respective owner

Related posts about c++

Related posts about atl