From 03ec218326dc857e926674ae737cfb2f69666a2d Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Mon, 9 Oct 2006 15:04:07 +0100 Subject: [PATCH] oleaut32: Implement ITypeInfo_CreateInstance. --- dlls/oleaut32/typelib.c | 48 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c index 52ce8b4480d..8ebfd0e185f 100644 --- a/dlls/oleaut32/typelib.c +++ b/dlls/oleaut32/typelib.c @@ -5867,11 +5867,53 @@ static HRESULT WINAPI ITypeInfo_fnAddressOfMember( ITypeInfo2 *iface, * (coclass). */ static HRESULT WINAPI ITypeInfo_fnCreateInstance( ITypeInfo2 *iface, - IUnknown *pUnk, REFIID riid, VOID **ppvObj) + IUnknown *pOuterUnk, REFIID riid, VOID **ppvObj) { ITypeInfoImpl *This = (ITypeInfoImpl *)iface; - FIXME("(%p) stub!\n", This); - return S_OK; + HRESULT hr; + TYPEATTR *pTA; + + TRACE("(%p)->(%p, %s, %p)\n", This, pOuterUnk, debugstr_guid(riid), ppvObj); + + *ppvObj = NULL; + + if(pOuterUnk) + { + WARN("Not able to aggregate\n"); + return CLASS_E_NOAGGREGATION; + } + + hr = ITypeInfo_GetTypeAttr(iface, &pTA); + if(FAILED(hr)) return hr; + + if(pTA->typekind != TKIND_COCLASS) + { + WARN("CreateInstance on typeinfo of type %x\n", pTA->typekind); + hr = E_INVALIDARG; + goto end; + } + + hr = S_FALSE; + if(pTA->wTypeFlags & TYPEFLAG_FAPPOBJECT) + { + IUnknown *pUnk; + hr = GetActiveObject(&pTA->guid, NULL, &pUnk); + TRACE("GetActiveObject rets %08lx\n", hr); + if(hr == S_OK) + { + hr = IUnknown_QueryInterface(pUnk, riid, ppvObj); + IUnknown_Release(pUnk); + } + } + + if(hr != S_OK) + hr = CoCreateInstance(&pTA->guid, NULL, + CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, + riid, ppvObj); + +end: + ITypeInfo_ReleaseTypeAttr(iface, pTA); + return hr; } /* ITypeInfo::GetMops