PyObject *PyIGlobalInterfaceTable::GetInterfaceFromGlobal(PyObject *self, PyObject *args)
{
	PyObject *obriid = NULL;
	DWORD dwCookie;
	IID riid;
	void* ppv;
	HRESULT hr;

	IGlobalInterfaceTable *pIGIT = GetI(self);
	if ( pIGIT == NULL )
	{
		return NULL;
	}
	if (!PyArg_ParseTuple(args, "lO:GetInterfaceFromGlobal", &dwCookie, &obriid) )
	{
		return NULL;
	}
	BOOL bPythonIsHappy = TRUE;
	if (!PyWinObject_AsIID(obriid, &riid)) bPythonIsHappy = FALSE;
	
	if(!bPythonIsHappy)
	{
		return NULL;
	}
	PY_INTERFACE_PRECALL;
	hr = pIGIT->GetInterfaceFromGlobal( dwCookie, riid, &ppv );
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
	{
		return PyCom_BuildPyException(hr, pIGIT, IID_IGlobalInterfaceTable );
	}
	return PyCom_PyObjectFromIUnknown((IUnknown*)ppv, riid, FALSE);
}
HRESULT
AgileReference::Resolve(REFIID aIid, void** aOutInterface)
{
  MOZ_ASSERT(aOutInterface);
  MOZ_ASSERT(mAgileRef || mGitCookie);

  if (!aOutInterface) {
    return E_INVALIDARG;
  }

  *aOutInterface = nullptr;

  if (mAgileRef) {
    // IAgileReference lets you directly resolve the interface you want...
    return mAgileRef->Resolve(aIid, aOutInterface);
  }

  if (!mGitCookie) {
    return E_UNEXPECTED;
  }

  IGlobalInterfaceTable* git = ObtainGit();
  MOZ_ASSERT(git);
  if (!git) {
    return E_UNEXPECTED;
  }

  RefPtr<IUnknown> originalInterface;
  HRESULT hr = git->GetInterfaceFromGlobal(mGitCookie, mIid,
                                           getter_AddRefs(originalInterface));
  if (FAILED(hr)) {
    return hr;
  }

  if (aIid == mIid) {
    originalInterface.forget(aOutInterface);
    return S_OK;
  }

  // ...Whereas the GIT requires us to obtain the same interface that we
  // requested and then QI for the desired interface afterward.
  return originalInterface->QueryInterface(aIid, aOutInterface);
}