Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 243779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:56:59+00:00 2026-05-11T20:56:59+00:00

This is somewhat related to another question that I’ve asked that I’ve pretty much

  • 0

This is somewhat related to another question that I’ve asked that I’ve pretty much figured out. The last piece of the puzzle is using CoCreateInstance() instead of GetActiveObject(). I don’t want to use an existing instance of EnvDTE, so I call CoCreateInstance, which properly fires off a new instance of VisualStudio. CoCreateInstance() calls AddRef() and I store the output pointer in a CComPtr, which properly calls Release on destruction. When this Release() happens, lo and behold the instance of VS closes! Of course it does because the refcount is at zero. What I’m wanting to do is have the new process own that last instance, so when the user closes VS with the Close (X) button it will destroy the COM object.

There are a few things I have tried:
1. Calling Detach() on my CComPtr, so the object lives on. Sure it works, however, closing VS with the close button doesn’t actually kill the process (it’s still running in the Task Manager list).
2. Launch a separate process of VS and then use ROT to find the new instance. This is ugly because I have to wait an indeterminate amount of time for the application to launch before trying to find the new instance of the COM object.
3. Use a global or static CComPtr, and manually destroy the object when my app closes. I’d rather not do it this way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:57:00+00:00Added an answer on May 11, 2026 at 8:57 pm

    So, I’ve figured this out for the specific case of creating an VisualStudio.DTE object using CoCreateInstance. The DTE object returned has a UserControl property, which can be set to TRUE. When you set this to TRUE, then a Release() of the CComPtr that holds the DTE object doesn’t destroy the instance:

    #define RETURN_ON_FAIL( expression ) \
    result = ( expression );    \
    if ( FAILED( result ) )     \
        return false;           \
    else // To prevent danging else condition
    
    HRESULT result;
    CLSID clsid;
    CComPtr<IUnknown> punk = NULL;
    
    CComPtr<EnvDTE::_DTE> dte = NULL;
    RETURN_ON_FAIL( ::CLSIDFromProgID(L"VisualStudio.DTE", &clsid) );
    RETURN_ON_FAIL( ::CoCreateInstance( clsid, NULL, CLSCTX_LOCAL_SERVER, EnvDTE::IID__DTE, (LPVOID*)&punk ) );
    dte = punk;
    dte->put_UserControl( TRUE );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is somewhat related to another question I've asked but I figure why not
This is somewhat related to another question I asked: Translate GPS coordinates to location
(In Python 3.1) (Somewhat related to another question I asked , but this question
[This question is somewhat related to this question , but the answers are not...]
Although somewhat related to this question , I have what I think is a
So this question is (somewhat distantly) related to this previous question: Best way to
I think this is somewhat related to this question , but being not sure
somewhat related to: libxml2 from java yes, this question is rather long-winded - sorry.
Somewhat related to this question . I'm trying to create a window with two
I realize there is a somewhat related thread on this here: Loading assemblies and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.