Compartilhar via


AtlAdvise

 

Creates a connection between an object's connection point and a client's sink.

Important

This function cannot be used in applications that execute in the Windows Runtime.

Syntax

      HRESULT AtlAdvise(
IUnknown* pUnkCP,
IUnknown* pUnk,
const IID& iid,
LPDWORD pdw 
);

Parameters

  • pUnkCP
    [in] A pointer to the IUnknown of the object the client wants to connect with.

  • pUnk
    [in] A pointer to the client's IUnknown.

  • iid
    [in] The GUID of the connection point. Typically, this is the same as the outgoing interface managed by the connection point.

  • pdw
    [out] A pointer to the cookie that uniquely identifies the connection.

Return Value

A standard HRESULT value.

Remarks

The sink implements the outgoing interface supported by the connection point. The client uses the pdw cookie to remove the connection by passing it to AtlUnadvise.

Example

LPUNKNOWN m_pSourceUnk;
LPUNKNOWN m_pSinkUnk;
DWORD m_dwCustCookie;

// create source object
HRESULT hr = CoCreateInstance (CLSID_MyComponent, NULL, CLSCTX_ALL, 
   IID_IUnknown, (LPVOID*)&m_pSourceUnk);
ATLASSERT(SUCCEEDED(hr));

// Create sink object.  CMySink is a CComObjectRootEx-derived class 
// that implements the event interface methods.
CComObject<CMySink>* pSinkClass;
CComObject<CMySink>::CreateInstance(&pSinkClass);
hr = pSinkClass->QueryInterface (IID_IUnknown, (LPVOID*)&m_pSinkUnk);
ATLASSERT(SUCCEEDED(hr));

hr = AtlAdvise (m_pSourceUnk, m_pSinkUnk, __uuidof(_IMyComponentEvents), &m_dwCustCookie);
ATLASSERT(SUCCEEDED(hr));    

Requirements

Header: atlbase.h

See Also

Connection Point Global Functions