Solved

How do I use CoGetClassObject?

Posted on 1997-03-26
1
1,862 Views
Last Modified: 2013-11-20
I am trying to obtain an interface to an Automation Server which resides in a separate executable on the same machine (for example, Word (it's not word, but its the same type of server)).

I am successful at getting an interface and can then call methods with the IDispatch::Invoke method, however it starts a new instance of the EXECUTABLE each time I use CoGetClassObject (once per program run), even if the app is running already.

The SDK says it will first look for the server, and only create one when it is not available.  

This is all done in C++ (MSVC 4.2).  If I do the same thing in vb (dim object, etc.) it uses the instance of my server already running).    Here is a snipet of code:

LPCLASSFACTORY pIClassFactory;

   hr = CoGetClassObject( Clsid,
                          CLSCTX_INPROC_SERVER,
                          NULL,
                          IID_IClassFactory,
                          (LPVOID *)&pIClassFactory );

   if (SUCCEEDED(hr))
      {
      LPUNKNOWN   pUnk=NULL;

      pIClassFactory->CreateInstance(pUnk, IID_IDispatch, (LPVOID *)&m_pDispatch);
      pIClassFactory->Release();

      return TRUE;
      }

return FALSE;  // (failture)
0
Comment
Question by:tdietz
1 Comment
 
LVL 2

Accepted Solution

by:
sapek earned 50 total points
Comment Utility
I don't that think using CoGetClassObject followed by IClassFactory::CreateInstance is different then calling CoCreateInstance (as I know CoCreateInstance internaly just does call CoGetClassObject and IClassFactory::CreateInstance). So you should not expect that a running instance of a server will be used.
I am not but I think that you should use ROT (running object table) to get an instance of a running server. You can access it through GetRunningObjectTable.

Adam

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now