Create the ATL COM DLL
Start Visual Studio .NET
Start a "New Project"
Select "Visual C++ Projects"
Select "ATL Project"
Click "OK"
Name the project "ATLDemo"
Click "OK"
As the default option is "Dynamic-link library (DLL)", Click "Next
Select Support MFC, click "Finish"
Add ATL COM Control
Right-click on the project name
Go to the "Add" option
Select "Add Class…"
Select "ATL COM Control"
Select Options as per Requirement, Click "Finish"
Add Method in ATL Contol
Right-click on the interface class named in Class View
Go to "Add"
Select "Add Method"
Enter method name
Check the "in" checkbox under the "Parameter attributes" section
Select BSTR for the parameter type
Name the parameter "bsName"
Click "Add"
Click "Finish"
Code to Register COM Object in Running Object Table
STDMETHODIMP CPPName::FunctionName(BSTR bsName)
{
ConInitialize(NULL);
CComPtr<IBindCtx> pbc;
CComPtr<IRunningObjectTable> pROT;
CComPtr<IMoniker> spMoniker;
CComPtr<IUnknown> spUnk;
CComPtr<IEnumMoniker> IMonikerEnum;
DWORD dWCookie;
CreateBindCtx(0,&pbc);
pbc->GetRunningObjectTable(&pROT);
CreateItemMoniker(NULL,bsName,&spMoniker);
QueryInterface(IID_IUNKNOWN, (void**)&spUnk);
pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, spUnk, spMoniker, &dWCookie);
CoUnInitialize();
}
Use Register COM Object in other COM Object
STDMETHODIMP CPPName::FunctionName(BSTR bsName)
{
ConInitialize(NULL);
CComPtr<IBindCtx> pbc;
CComPtr<IRunningObjectTable> pROT;
CComPtr<IMoniker> spMoniker;
CComPtr<IUnknown> spUnk;
CComPtr<IEnumMoniker> IMonikerEnum;
DWORD dWCookie;
CreateBindCtx(0,&pbc);
pbc->GetRunningObjectTable(&pROT);
<Loop For Moniker, Checking Name Provided>
hr = pROT->GetObject(pMon, &pInterface);
<IF Get Name of Moniker> == bsName>
hr = pInterface->QueryInterface(IID_IAttach, (void **)pAttach);
<End IF>
<Loop End>
}
"pAttach" object having access to object that is Registered.
By this "pAttach" having access to methods of object.
Problem:
I am having One Exe with Object that is registed.
In another exe I am using another object giving name that is already registered.
Now my task is from first exe when i m clicking left button then second exe should get message.
Is there any way to access register object's event in another exe??