Beispiel #1
0
HRESULT CJSExtender::SinkObject(CString strPrefix, IDispatch *pUnk, LCID lcid)
{
	if (!pUnk || strPrefix==_T(""))
		return E_INVALIDARG;

	HRESULT hr = S_FALSE;
	GUID iid = GUID_NULL;

	if (theApp.m_pEventProxy) 
		theApp.m_pEventProxy->GetConnectionInterface(&iid);
	else
	{
		CComQIPtr<IConnectionPointContainer> pContainer(pUnk);
		if (pContainer == nullptr)
			return 0;
		GUID libid;
		WORD wMajorVer = 1;
		WORD wMinorVer = 0;
		hr = AtlGetObjectSourceInterface(pUnk, &libid, &iid, &wMajorVer, &wMinorVer);
		if (iid == GUID_NULL)
		{
			IConnectionPoint* pConnectionPoint = nullptr;
			IEnumConnectionPoints* pEnum = nullptr;
			HRESULT hr = pContainer->EnumConnectionPoints(&pEnum);
			if (pEnum)
			{
				ULONG uFetched;
				while (S_OK == (pEnum->Next(1, &pConnectionPoint, &uFetched)) && uFetched >= 1)
				{
					hr = pConnectionPoint->GetConnectionInterface(&iid);
					if (hr == S_OK)
					{
						pConnectionPoint->Release();
						pConnectionPoint = nullptr;
						break;
					}
					pConnectionPoint->Release();
					pConnectionPoint = nullptr;
				}
				pEnum->Release();
			}
		}
	}
	if (iid != GUID_NULL)
		new CJSProxyObj(this, pUnk, iid, strPrefix);

	return S_OK;
}
// @pymethod <o PyIID>|PyIConnectionPoint|GetConnectionInterface|Retrieves the IID of the interface represented by the connection point.
PyObject *PyIConnectionPoint::GetConnectionInterface(PyObject *self, PyObject *args)
{
	if ( !PyArg_ParseTuple(args, ":GetConnectionInterface") )
		return NULL;

	IConnectionPoint *pICP = GetI(self);
	if ( pICP == NULL )
		return NULL;

	IID iid;
	PY_INTERFACE_PRECALL;
	HRESULT hr = pICP->GetConnectionInterface(&iid);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return SetPythonCOMError(self,hr);

	return PyWinObject_FromIID(iid);
}
Beispiel #3
0
void EnumConnectionPoint(IDispatch *pDisp, LPCSTR comment)
{
	if (!pDisp) return;
	HRESULT hr = S_OK;

	USES_CONVERSION;
	IConnectionPointContainer *spCPC = NULL;
	IConnectionPoint *spCP = NULL;
	IEnumConnectionPoints *ppEnum = NULL;
	IID id;
	LPOLESTR strGUID = 0;
	CComBSTR bstrId = NULL;

	if(comment) cout << comment << _T(" ");
	cout << _T("ConnectionPoint: [");
	hr = pDisp->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&spCPC));
	if (SUCCEEDED(hr) && spCPC)
	{
		hr = spCPC->EnumConnectionPoints(&ppEnum);
		while(SUCCEEDED(ppEnum->Next(1, &spCP, NULL)) && spCP) 
		{
			spCP->GetConnectionInterface(&id);
			// 注意此处StringFromIID的正确用法, 否则会在Debug状态下出错: user breakpoint called from code 0x7c901230
			StringFromIID(id, &strGUID);
			bstrId = strGUID;
			CoTaskMemFree(strGUID);
			cout << (bstrId ? OLE2CT(bstrId) : _T("")) << _T(", ");
		}
	}
	cout << "]" << endl;
	if(spCP) spCP->Release();
	if(ppEnum) ppEnum->Release();
	if(spCPC) spCPC->Release();
/*
	{9bfbbc02-eff1-101a-84ed-00aa00341d07}	IPropertyNotifySink
	{3050f3c4-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents
	{3050f620-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents2
	{00020400-0000-0000-c000-000000000046}	IDispatch
	{1dc9ca50-06ef-11d2-8415-006008c3fbfc}	ITridentEventSink
	{d27cdb6d-ae6d-11cf-96b8-444553540000}	ShockwaveFlashObjects::_IShockwaveFlashEvents
*/
}