How to interact between two COM objects using a desktop table (ROT)?

I have two COM objects written in C ++ and ATL. There is in one library, and I know their IID and CLID.

I can’t find an example of this simple relationship between two simple COM objects. How to create IMoniker and how to add it to ROT? And then, how to get the pointer of this object, in another COM in another process / thread?

Can anyone provide a small example?

EDIT : Additional Information:

I am writing an add-in for IE. There are two COM objects that are completely unrelated to loading IE for different purposes. One of them is BHO (Ober Browser Helper Obect), the other is Asynchronous Pluggable Protocol (APP). I found that I can communicate through ROT here .

+7
source share
1 answer

Try using CreateItemMoniker instead of CreatePointerMoniker - it allows you to specify a name for your object in ROT.

You should be able to register your property as follows:

DWORD RegisterInROT(LPCWSTR szObjName, IUnknown* pObj) { DWORD dwCookie = 0; CComPtr<IRunningObjectTable> pROT; if (GetRunningObjectTable(0, &pROT) == S_OK) { CComPtr<IMoniker> pMoniker; if (CreateItemMoniker(NULL, szObjName, &pMoniker) == S_OK) if (pROT->Register(0, pObj, pMoniker, &dwCookie) == S_OK) return dwCookie; } return 0; } 

If you do not want your object to be automatically killed when there are no more references to it, you can specify ROTFLAGS_REGISTRATIONKEEPSALIVE instead of 0 ( check in on MSDN ). The function returns a cookie, which you can use to explicitly remove your object from the ROT later as follows:

 void RevokeFromROT(DWORD dwCookie) { CComPtr<IRunningObjectTable> pROT; if (GetRunningObjectTable(0, &pROT) == S_OK) pROT->Revoke(dwCookie); } 

You can get the object from ROT like this (you should use the same name that you used to register the object, of course =)

 void GetObjectFromROT(LPCWSTR szObjName, IUnknown** pObj) { CComPtr<IRunningObjectTable> pROT; if (GetRunningObjectTable(0, &pROT) == S_OK) { CComPtr<IMoniker> pMoniker; if (CreateItemMoniker(NULL, szObjName, &pMoniker) == S_OK) pROT->GetObject(pMoniker, pObj); } } 
+6
source

All Articles