Compartilhar via


AtlGetObjectSourceInterface

Call this function to retrieve information about the default source interface of an object.

Important

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

ATLAPI AtlGetObjectSourceInterface( 
IUnknown* punkObj, 
GUID* plibid, 
IID* piid, 
unsigned short* pdwMajor, 
unsigned short* pdwMinor 
);

Parameters

  • punkObj
    [in] A pointer to the object for which information is to be returned.

  • plibid
    [out] A pointer to the LIBID of the type library containing the definition of the source interface.

  • piid
    [out] A pointer to the interface ID of the object's default source interface.

  • pdwMajor
    [out] A pointer to the major version number of the type library containing the definition of the source interface.

  • pdwMinor
    [out] A pointer to the minor version number of the type library containing the definition of the source interface.

Return Value

A standard HRESULT value.

Remarks

AtlGetObjectSourceInterface can provide you with the interface ID of the default source interface, along with the LIBID and major and minor version numbers of the type library describing that interface.

Note

For this function to successfully retrieve the requested information, the object represented by punkObj must implement IDispatch (and return type information through IDispatch::GetTypeInfo) plus it must also implement either IProvideClassInfo2 or IPersist. The type information for the source interface must be in the same type library as the type information for IDispatch.

Example

The example below shows how you might define an event sink class, CEasySink, that reduces the number of template arguments that you can pass to IDispEventImpl to the bare essentials. EasyAdvise and EasyUnadvise use AtlGetObjectSourceInterface to initialize the IDispEventImpl members before calling DispEventAdvise or DispEventUnadvise.

template <UINT nID, class T>
class CEasySink : public IDispEventImpl<nID, T>
{
public:
   HRESULT EasyAdvise(IUnknown* pUnk) 
   { 
      AtlGetObjectSourceInterface(pUnk,
         &m_libid, &m_iid, &m_wMajorVerNum, &m_wMinorVerNum);
      return DispEventAdvise(pUnk, &m_iid);
   }
   HRESULT EasyUnadvise(IUnknown* pUnk) 
   {
      AtlGetObjectSourceInterface(pUnk,
         &m_libid, &m_iid, &m_wMajorVerNum, &m_wMinorVerNum);
      return DispEventUnadvise(pUnk, &m_iid);
   }
};

Requirements

Header: atlcom.h

See Also

Reference

IDispEventImpl Class

IDispEventSimpleImpl Class

Other Resources

Composite Control Global Functions