Solved

How do I use CoGetClassObject?

Posted on 1997-03-26
1
1,930 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 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