// @pymethod int|PyIDataObject|DAdvise|Connects the object to an interface that will receive notifications when its data changes // @rdesc Returns a unique number that is used to identify the connection PyObject *PyIDataObject::DAdvise(PyObject *self, PyObject *args) { IDataObject *pIDO = GetI(self); if ( pIDO == NULL ) return NULL; FORMATETC formatetc; PyObject *obpformatetc; // @pyparm <o PyFORMATETC>|pformatetc||Defines the type of data for which the sink will receive notifications. // @pyparm int|advf||Combination of values from ADVF enum. (which currently do not appear in any of the constants modules!) // @pyparm <o PyIAdviseSink>|pAdvSink||Currently this interface is not wrapped. PyObject *obpAdvSink; DWORD advf; IAdviseSink *pAdvSink; if ( !PyArg_ParseTuple(args, "OlO:DAdvise", &obpformatetc, &advf, &obpAdvSink) ) return NULL; BOOL bPythonIsHappy = TRUE; if (bPythonIsHappy && !PyObject_AsFORMATETC( obpformatetc, &formatetc )) bPythonIsHappy = FALSE; if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpAdvSink, IID_IAdviseSink, (void **)&pAdvSink, TRUE /* bNoneOK */)) bPythonIsHappy = FALSE; if (!bPythonIsHappy) return NULL; DWORD dwConnection; HRESULT hr; PY_INTERFACE_PRECALL; hr = pIDO->DAdvise( &formatetc, advf, pAdvSink, &dwConnection ); PY_INTERFACE_POSTCALL; if (pAdvSink) pAdvSink->Release(); if ( FAILED(hr) ) return PyCom_BuildPyException(hr, pIDO, IID_IDataObject ); return PyInt_FromLong(dwConnection); }
TEST(iDataObjectTest,Simple) { IDataObject *pDataObject = NULL; CreateDataObject(NULL,NULL,&pDataObject,0); FORMATETC ftc; ftc.cfFormat = CF_TEXT; ftc.dwAspect = DVASPECT_CONTENT; ftc.lindex = -1; ftc.ptd = NULL; ftc.tymed = TYMED_HGLOBAL; EXPECT_EQ(DV_E_FORMATETC,pDataObject->QueryGetData(&ftc)); EXPECT_EQ(E_NOTIMPL,pDataObject->DAdvise(NULL,ADVF_NODATA,NULL,NULL)); EXPECT_EQ(OLE_E_ADVISENOTSUPPORTED,pDataObject->DUnadvise(0)); EXPECT_EQ(OLE_E_ADVISENOTSUPPORTED,pDataObject->EnumDAdvise(NULL)); }