Recently, I have learned COM technology, I feel that it is difficult to connect the accessible object. After reading the book of Pan, I wrote a simple example with ATL: a COM component: Declare the connectable object to be implemented [UUID (87EA0963-F479-4ABC -95DD-DF0F081B73D2), Helpstring ("LJ Class")] Interface_iwlevents: iunknown {[Helpstring ("Method Tongku")] HRESULT JINGjing ();}; Declaration CoClass LJ {[default] interface ilj; [Source] ] interface _IWLEvents;}; Next generation connectable object with ATL, ATL automatically generates the activation function JINGJING follows: class CProxy_IWLEvents: public IConnectionPointImpl {// Warning this class may be recreated By the wizard.public: hResult fire_jingjing () {hResult ret; t * pt = static_cast (this); int nConnectionIndex; int nConnectionS = m_vec.getsize (); // Traverse the client for Connect nConnectionIndex = 0; nConnectionIndex Lock (); CComPtr sp = m_vec.GetAt (nConnectionIndex); pT-> Unlock (); _IWLEvents * p_IWLEvents = reinterpret_cast <_IWLEvents *> (sp. p); if (p_iwlevents! = null) Ret = p_iwlevents-> jingjing (); // call Client programs, associated with clients} return ret;}}; two clients are implemented with a dialog box program, first to implement interface Iwlevents class Ciwl: public_iwlevents {stdmethodimp queryinterface (Refiid IID, LPVOID * PP) {* pp = this; return s_ok;} stdmethodimp_ (ulong) addRef () {return 2;} stdmethodimp_ (ulong) release () {return 1;} stdmethodimp jingjing () {AFXMESSAGEBOX ("Return to Client") ; return 1;}}; calling process implemented by a button event: void CShowDlg :: OnButton1 () {CoInitialize (NULL); ILJ * p; IConnectionPointContainer * pContainer = NULL; IConnectionPoint * pPoint = NULL; HRESULT hr = CoCreateInstance (CLSID_LJ , NULL, CLSCTX_INPROC_SERVER, IID_ILJ, (VOID **) & P); if (succeeded (hr)) {P->
QueryInterface (IID_IConnectionPointContainer, (void **) & pContainer); if (SUCCEEDED (hr)) {hr = pContainer-> FindConnectionPoint (IID__IWLEvents, & pPoint); if (SUCCEEDED (hr)) {DWORD dwCookie; CIWL * m_pDuckInt = new CIWL; HR = ppoint-> advise (m_pduckint, & dwcookie); if (succeeded (hr)) {p-> fire (); ppoint-> release ();} ppoint-> unadvise (dwcookie);} Couninitialize ();} It is a newbie, I hope that the old birds have more advice.