Solved

How do I use CoGetClassObject?

Posted on 1997-03-26
1
1,901 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
ID: 1300700
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

837 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