Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I use CoGetClassObject?

Posted on 1997-03-26
1
Medium Priority
?
2,011 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 150 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

596 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