Solved

How do I use CoGetClassObject?

Posted on 1997-03-26
1
1,893 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 72
Doc'in system (example?) BA 7 112
fizzArray2 challenge 1 82
sumHeights2  challenge 7 107
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 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