Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

COM server and client

Posted on 1998-07-21
2
Medium Priority
?
637 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
ID: 1251750
Edited text of question
0
 
LVL 1

Accepted Solution

by:
eburley earned 400 total points
ID: 1251751
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

916 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