Solved

COM server and client

Posted on 1998-07-21
2
627 Views
Last Modified: 2012-08-13
I am implementing a COM Server
In this server was implementing IUnknown and IClassFactory
interfaces.
I register server object in the Running Object Table with a moniker and pointer to the IClassFactory interface:

LPMONIKER            lpMon;
DWORD                dwReg;
WCHAR            lpszDelim[MAX_PATH];
WCHAR            lpszItem[MAX_PATH];
 LPUNKNOWN   punk = NULL;
LPRUNNINGOBJECTTABLE lpRot;

       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, "!", -1,
                                                     lpszDelim, MAX_PATH);
       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,                                                     "Name1", -1,lpszItem, MAX_PATH);

     CreateItemMoniker(lpszDelim, lpszItem, &lpMon);
     GetRunningObjectTable(0, &lpRot);
     if(lpRot->IsRunning(lpMon) == S_OK)
         {
             MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,                                                            "Name2", -1,lpszItem, MAX_PATH);
            CreateItemMoniker(lpszDelim, lpszItem, &lpMon);
         }
    lpRot->Register(0, (IUnknown *)&classfactory,lpMon, &dwReg);
  .....                                          lpMon, &dwReg);
  .....

In the client application I want to get a server object via it moniker
from Running Object Table:

LPMONIKER            lpMon;
DWORD                dwReg;
WCHAR            lpszDelim[MAX_PATH];
WCHAR            lpszItem[MAX_PATH];
 LPUNKNOWN   punk = NULL;
LPRUNNINGOBJECTTABLE lpRot;
LPCLASSFACTORY pcf = NULL;

       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, "!", -1,
                                                     lpszDelim, MAX_PATH);
       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,                                                     "Name1", -1,lpszItem, MAX_PATH);

     GetRunningObjectTable(0, &lpRot);
     if(lpRot->IsRunning(lpMon) == S_OK)
       {
          lpRot->GetObject(lpMon, &punk);
          pcf = (LPCLASSFACTORY)punk;
          hr = pcf->CreateInstance(NULL, IID_IUnknown,                                                             (LPVOID*)&punk);
        }

In spite of that pointer (pcf) to object is not NULL I got Access Violation when I try to use this pointer. So I don't get a right pointer.
What is a mistake ?
What can I do for geting pointer to one definity COM server object when same COM server (whith same CLSID) is running more than
once?
0
Comment
Question by:atkach
2 Comments
 

Author Comment

by:atkach
Comment Utility
Edited text of question
0
 
LVL 1

Accepted Solution

by:
eburley earned 100 total points
Comment Utility
you can't just cast classfactory to an IUnknown pointer.  and you can't cast it back to an LPClassFactory interface.  You must use QueryInterface (the COM version of casting).  So register the IUnknown with the ROT, and when you get it from the ROT in the client code, QueryInterface back to a class factory.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

772 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

9 Experts available now in Live!

Get 1:1 Help Now