开发者

How to call interface API from within COM server

开发者 https://www.devze.com 2022-12-31 04:49 出处:网络
I have one com server with some interfaces exposing some API\'s COM class looks like below class ATL_NO_VTABLE CTask :

I have one com server with some interfaces exposing some API's

COM class looks like below

class ATL_NO_VTABLE CTask :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CTask, &CLSID_Task>,
    public ITask
{

public:
 STDMETHOD (Task)();
 STDMETHOD (ABC)();
...
}

Now this com server also contains one more class XYZ

ABC API needs to call XYZ functionality

 STDMETHODIMP ABC()
{
    XYZ xyz;
    xyz.dosomething();
}

dosomething function need to call com server Task function, like below

  class XYZ
       {
      public:
        void dosomething()
         {
        // need to call Task function
         }
        };

How can this be done? Do I need to CoCreateInstance ITask in dosomething?

I tried creating CTask taskl; in dosomething but it ga开发者_C百科ve some errors.


Class CTask is non-creatable since it doesn't implement IUnknown methods. You need to use one of ATL classes intended for serving as COM objects, for example CComObject:

CComPtr<ITask> newTask = new CComObject<CTask>();
0

精彩评论

暂无评论...
验证码 换一张
取 消