Solved

COM client , server

Posted on 1998-07-21
4
903 Views
Last Modified: 2012-05-05
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];

       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];

       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 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
4 Comments
 
LVL 3

Expert Comment

by:altena
ID: 1168168
This is a hard question...definitely.
0
 
LVL 8

Accepted Solution

by:
trestan earned 100 total points
ID: 1168169
There are many win32 functions that get certain information and store the information in a buffer. But the buffer size is unknow at the first time the function is called. So for these functions, they should be called twice. The buffer size is obtained at the first time, then memory is allocated to the buffer. At the second time, buffer has enough space to store information. Otherwise, violation may occur because unauthorized memory address is read or written. Your problem is in this case. So try to do as I suggest. Pls tell me if there is more questions.
0
 

Author Comment

by:atkach
ID: 1168170
It is not help.
I have a problem with pointer pcf, wich I got after exeqution
GetObject function.
0
 

Author Comment

by:atkach
ID: 1168171
Thank's. I am allready got an answer.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

746 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