--- trunk/reactos/lib/oleaut32/typelib.c 2005-01-12 19:51:26 UTC (rev 12986)
+++ trunk/reactos/lib/oleaut32/typelib.c 2005-01-12 19:51:40 UTC (rev 12987)
@@ -74,7 +74,6 @@
#include "wine/unicode.h"
#include "objbase.h"
-#include "ole2disp.h"
#include "typelib.h"
#include "wine/debug.h"
#include "variant.h"
@@ -848,7 +847,7 @@
{
ITypeLib2Vtbl *lpVtbl;
ITypeCompVtbl *lpVtblTypeComp;
- UINT ref;
+ ULONG ref;
TLIBATTR LibAttr; /* guid,lcid,syskind,version,flags */
/* strings can be stored in tlb as multibyte strings BUT they are *always*
@@ -959,7 +958,7 @@
{
ITypeInfo2Vtbl *lpVtbl;
ITypeCompVtbl *lpVtblTypeComp;
- UINT ref;
+ ULONG ref;
TYPEATTR TypeAttr ; /* _lots_ of type information. */
ITypeLibImpl * pTypeLib; /* back pointer to typelib */
int index; /* index in this typelib; */
@@ -989,7 +988,7 @@
static struct ITypeInfo2Vtbl tinfvt;
static struct ITypeCompVtbl tcompvt;
-static ITypeInfo2 * WINAPI ITypeInfo_Constructor();
+static ITypeInfo2 * WINAPI ITypeInfo_Constructor(void);
typedef struct tagTLBContext
{
@@ -1277,7 +1276,7 @@
static void dump_TypeInfo(ITypeInfoImpl * pty)
{
- TRACE("%p ref=%u\n", pty, pty->ref);
+ TRACE("%p ref=%lu\n", pty, pty->ref);
TRACE("attr:%s\n", debugstr_guid(&(pty->TypeAttr.guid)));
TRACE("kind:%s\n", typekind_desc[pty->TypeAttr.typekind]);
TRACE("fct:%u var:%u impl:%u\n",
@@ -1331,7 +1330,51 @@
HeapFree(GetProcessHeap(), 0, ptr);
}
+/* deep copy a typedesc */
+static void copy_typedesc(TYPEDESC *out, const TYPEDESC *in)
+{
+ out->vt = in->vt;
+ switch(in->vt) {
+ case VT_PTR:
+ out->u.lptdesc = HeapAlloc(GetProcessHeap(), 0, sizeof(TYPEDESC));
+ copy_typedesc(out->u.lptdesc, in->u.lptdesc);
+ break;
+ case VT_USERDEFINED:
+ out->u.hreftype = in->u.hreftype;
+ break;
+ case VT_CARRAY:
+ out->u.lpadesc = HeapAlloc(GetProcessHeap(), 0, sizeof(ARRAYDESC) +
+ (in->u.lpadesc->cDims - 1) * sizeof(SAFEARRAYBOUND));
+ copy_typedesc(&out->u.lpadesc->tdescElem, &in->u.lpadesc->tdescElem);
+ out->u.lpadesc->cDims = in->u.lpadesc->cDims;
+ memcpy(out->u.lpadesc->rgbounds, in->u.lpadesc->rgbounds, in->u.lpadesc->cDims * sizeof(SAFEARRAYBOUND));
+ break;
+ default:
+ break;
+ }
+}
+/* free()s any allocated memory pointed to by the tdesc. NB does not
+ free the tdesc itself - this is because the tdesc is typically part
+ of a larger structure */
+static void free_deep_typedesc(TYPEDESC *tdesc)
+{
+ switch(tdesc->vt) {
+ case VT_PTR:
+ free_deep_typedesc(tdesc->u.lptdesc);
+ HeapFree(GetProcessHeap(), 0, tdesc->u.lptdesc);
+ tdesc->u.lptdesc = NULL;
+ break;
+ case VT_CARRAY:
+ free_deep_typedesc(&tdesc->u.lpadesc->tdescElem);
+ HeapFree(GetProcessHeap(), 0, tdesc->u.lpadesc);
+ tdesc->u.lpadesc = NULL;
+ break;
+ default:
+ break;
+ }
+}
+
/**********************************************************************
*
* Functions for reading MSFT typelibs (those created by CreateTypeLib2)
@@ -1473,7 +1516,7 @@
if(offset <0) { /* data are packed in here */
V_VT(pVar) = (offset & 0x7c000000 )>> 26;
- V_UNION(pVar, iVal) = offset & 0xffff;
+ V_UNION(pVar, iVal) = offset & 0x3ffffff;
return;
}
MSFT_ReadLEWords(&(V_VT(pVar)), sizeof(VARTYPE), pcx,
@@ -1604,7 +1647,7 @@
* of this (first) part excluding this field. Then follow the records,
* for each member there is one record.
*
- * First entry is always the length of the record (excluding this
+ * First entry is always the length of the record (including this
* length word).
* Rest of the record depends on the type of the member. If there is
* a field indicating the member type (function variable intereface etc)
@@ -3391,10 +3434,11 @@
static ULONG WINAPI ITypeLib2_fnAddRef( ITypeLib2 *iface)
{
ITypeLibImpl *This = (ITypeLibImpl *)iface;
+ ULONG ref = InterlockedIncrement(&This->ref);
- TRACE("(%p)->ref was %u\n",This, This->ref);
+ TRACE("(%p)->ref was %lu\n",This, ref - 1);
- return ++(This->ref);
+ return ref;
}
/* ITypeLib::Release
@@ -3402,12 +3446,11 @@
static ULONG WINAPI ITypeLib2_fnRelease( ITypeLib2 *iface)
{
ITypeLibImpl *This = (ITypeLibImpl *)iface;
+ ULONG ref = InterlockedDecrement(&This->ref);
- --(This->ref);
+ TRACE("(%p)->(%lu)\n",This, ref);
- TRACE("(%p)->(%u)\n",This, This->ref);
-
- if (!This->ref)
+ if (!ref)
{
/* remove cache entry */
TRACE("removing from cache list\n");
@@ -3450,7 +3493,7 @@
return 0;
}
- return This->ref;
+ return ref;
}
/* ITypeLib::GetTypeInfoCount
@@ -4067,12 +4110,12 @@
static ULONG WINAPI ITypeInfo_fnAddRef( ITypeInfo2 *iface)
{
ITypeInfoImpl *This = (ITypeInfoImpl *)iface;
+ ULONG ref = InterlockedIncrement(&This->ref);
- ++(This->ref);
ITypeLib2_AddRef((ITypeLib2*)This->pTypeLib);
- TRACE("(%p)->ref is %u\n",This, This->ref);
- return This->ref;
+ TRACE("(%p)->ref is %lu\n",This, ref);
+ return ref;
}
/* ITypeInfo::Release
@@ -4080,12 +4123,11 @@
static ULONG WINAPI ITypeInfo_fnRelease(ITypeInfo2 *iface)
{
ITypeInfoImpl *This = (ITypeInfoImpl *)iface;
+ ULONG ref = InterlockedDecrement(&This->ref);
- --(This->ref);
+ TRACE("(%p)->(%lu)\n",This, ref);
- TRACE("(%p)->(%u)\n",This, This->ref);
-
- if (This->ref) {
+ if (ref) {
/* We don't release ITypeLib when ref=0 becouse
it means that funtion is called by ITypeLi2_Release */
ITypeLib2_Release((ITypeLib2*)This->pTypeLib);
@@ -4113,7 +4155,7 @@
HeapFree(GetProcessHeap(),0,This);
return 0;
}
- return This->ref;
+ return ref;
}
/* ITypeInfo::GetTypeAttr
@@ -4127,8 +4169,18 @@
{
ITypeInfoImpl *This = (ITypeInfoImpl *)iface;
TRACE("(%p)\n",This);
- /* FIXME: must do a copy here */
- *ppTypeAttr=&This->TypeAttr;
+ *ppTypeAttr = HeapAlloc(GetProcessHeap(), 0, sizeof(**ppTypeAttr));
+ memcpy(*ppTypeAttr, &This->TypeAttr, sizeof(**ppTypeAttr));
+
+ if(This->TypeAttr.typekind == TKIND_ALIAS) /* need to deep copy typedesc */
+ copy_typedesc(&(*ppTypeAttr)->tdescAlias, &This->TypeAttr.tdescAlias);
+
+ if((*ppTypeAttr)->typekind == TKIND_DISPATCH && (*ppTypeAttr)->wTypeFlags & TYPEFLAG_FDUAL) {
+ (*ppTypeAttr)->cFuncs = (*ppTypeAttr)->cbSizeVft / 4; /* This should include all the inherited
+ funcs */
+ (*ppTypeAttr)->cbSizeVft = 28; /* This is always the size of IDispatch's vtbl */
+ (*ppTypeAttr)->wTypeFlags &= ~TYPEFLAG_FOLEAUTOMATION;
+ }
return S_OK;
}
@@ -4683,9 +4735,9 @@
UINT *pArgErr)
{
ITypeInfoImpl *This = (ITypeInfoImpl *)iface;
- TLBFuncDesc * pFDesc;
- TLBVarDesc * pVDesc;
int i;
+ unsigned int func_index, var_index;
+ TYPEKIND type_kind;
HRESULT hres;
TRACE("(%p)(%p,id=%ld,flags=0x%08x,%p,%p,%p,%p) partial stub!\n",
@@ -4693,31 +4745,30 @@
);
dump_DispParms(pDispParams);
- for(pFDesc=This->funclist; pFDesc; pFDesc=pFDesc->next)
- if (pFDesc->funcdesc.memid == memid) {
- if (pFDesc->funcdesc.invkind & dwFlags)
- break;
- }
-
- if (pFDesc) {
- if (TRACE_ON(typelib)) dump_TLBFuncDescOne(pFDesc);
- /* dump_FUNCDESC(&pFDesc->funcdesc);*/
- switch (pFDesc->funcdesc.funckind) {
+ hres = ITypeInfo2_GetFuncIndexOfMemId(iface, memid, dwFlags, &func_index);
+ if (SUCCEEDED(hres)) {
+ FUNCDESC *func_desc;
+
+ hres = ITypeInfo2_GetFuncDesc(iface, func_index, &func_desc);
+ if(FAILED(hres)) return hres;
+
+ switch (func_desc->funckind) {
case FUNC_PUREVIRTUAL:
case FUNC_VIRTUAL: {
DWORD res;
int numargs, numargs2, argspos, args2pos;
DWORD *args , *args2;
- VARIANT *rgvarg = HeapAlloc(GetProcessHeap(),0,sizeof(VARIANT)*pFDesc->funcdesc.cParams);
+ VARIANT *rgvarg = HeapAlloc(GetProcessHeap(), 0, sizeof(VARIANT) * func_desc->cParams);
memcpy(rgvarg,pDispParams->rgvarg,sizeof(VARIANT)*pDispParams->cArgs);
+ hres = S_OK;
numargs = 1; numargs2 = 0;
- for (i=0;i<pFDesc->funcdesc.cParams;i++) {
+ for (i = 0; i < func_desc->cParams; i++) {
if (i<pDispParams->cArgs)
- numargs += _argsize(pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt);
+ numargs += _argsize(func_desc->lprgelemdescParam[i].tdesc.vt);
else {
numargs += 1; /* sizeof(lpvoid) */
- numargs2 += _argsize(pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt);
+ numargs2 += _argsize(func_desc->lprgelemdescParam[i].tdesc.vt);
}
}
@@ -4726,14 +4777,14 @@
args[0] = (DWORD)pIUnk;
argspos = 1; args2pos = 0;
- for (i=0;i<pFDesc->funcdesc.cParams;i++) {
- int arglen = _argsize(pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt);
+ for (i = 0; i < func_desc->cParams; i++) {
+ int arglen = _argsize(func_desc->lprgelemdescParam[i].tdesc.vt);
if (i<pDispParams->cArgs) {
VARIANT *arg = &rgvarg[pDispParams->cArgs-i-1];
- TYPEDESC *tdesc = &pFDesc->funcdesc.lprgelemdescParam[i].tdesc;
- USHORT paramFlags = pFDesc->funcdesc.lprgelemdescParam[i].u.paramdesc.wParamFlags;
+ TYPEDESC *tdesc = &func_desc->lprgelemdescParam[i].tdesc;
+ USHORT paramFlags = func_desc->lprgelemdescParam[i].u.paramdesc.wParamFlags;
if (paramFlags & PARAMFLAG_FOPT) {
- if(i < pFDesc->funcdesc.cParams-pFDesc->funcdesc.cParamsOpt)
+ if(i < func_desc->cParams - func_desc->cParamsOpt)
ERR("Parameter has PARAMFLAG_FOPT flag but is not one of last cParamOpt parameters\n");
if(V_VT(arg) == VT_EMPTY
|| ((V_VT(arg) & VT_BYREF) && !V_BYREF(arg))) {
@@ -4748,23 +4799,23 @@
}
}
hres = _copy_arg(iface, tdesc, &args[argspos], arg, tdesc->vt);
- if (FAILED(hres)) return hres;
+ if (FAILED(hres)) goto func_fail;
argspos += arglen;
- } else if(pFDesc->funcdesc.lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FOPT) {
+ } else if(func_desc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FOPT) {
VARIANT *arg = &rgvarg[i];
- TYPEDESC *tdesc = &pFDesc->funcdesc.lprgelemdescParam[i].tdesc;
- if(i < pFDesc->funcdesc.cParams-pFDesc->funcdesc.cParamsOpt)
+ TYPEDESC *tdesc = &func_desc->lprgelemdescParam[i].tdesc;
+ if(i < func_desc->cParams - func_desc->cParamsOpt)
ERR("Parameter has PARAMFLAG_FOPT flag but is not one of last cParamOpt parameters\n");
- if(pFDesc->funcdesc.lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
+ if(func_desc->lprgelemdescParam[i].u.paramdesc.wParamFlags & PARAMFLAG_FHASDEFAULT)
FIXME("PARAMFLAG_FHASDEFAULT flag not supported\n");
V_VT(arg) = VT_ERROR;
V_ERROR(arg) = DISP_E_PARAMNOTFOUND;
arglen = _argsize(VT_ERROR);
hres = _copy_arg(iface, tdesc, &args[argspos], arg, tdesc->vt);
- if (FAILED(hres)) return hres;
+ if (FAILED(hres)) goto func_fail;
argspos += arglen;
} else {
- TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i].tdesc);
+ TYPEDESC *tdesc = &(func_desc->lprgelemdescParam[i].tdesc);
if (tdesc->vt != VT_PTR)
FIXME("set %d to pointer for get (type is %d)\n",i,tdesc->vt);
/*FIXME: give pointers for the rest, so propertyget works*/
@@ -4774,32 +4825,28 @@
if ((tdesc->vt == VT_PTR) &&
(tdesc->u.lptdesc->vt == VT_VARIANT) &&
pVarResult
- )
- args[argspos]= (DWORD)pVarResult;
+ )
+ args[argspos]= (DWORD)pVarResult;
argspos += 1;
args2pos += arglen;
}
}
- if (pFDesc->funcdesc.cParamsOpt < 0)
- FIXME("Does not support optional parameters (%d)\n",
- pFDesc->funcdesc.cParamsOpt
- );
+ if (func_desc->cParamsOpt < 0)
+ FIXME("Does not support optional parameters (%d)\n", func_desc->cParamsOpt);
- res = _invoke((*(FARPROC**)pIUnk)[pFDesc->funcdesc.oVft/4],
- pFDesc->funcdesc.callconv,
+ res = _invoke((*(FARPROC**)pIUnk)[func_desc->oVft/4],
+ func_desc->callconv,
numargs,
args
);
- HeapFree(GetProcessHeap(), 0, rgvarg);
-
if (pVarResult && (dwFlags & (DISPATCH_PROPERTYGET))) {
args2pos = 0;
- for (i=0;i<pFDesc->funcdesc.cParams-pDispParams->cArgs;i++) {
- int arglen = _argsize(pFDesc->funcdesc.lprgelemdescParam[i].tdesc.vt);
- TYPEDESC *tdesc = &(pFDesc->funcdesc.lprgelemdescParam[i+pDispParams->cArgs].tdesc);
- TYPEDESC i4_tdesc;
- i4_tdesc.vt = VT_I4;
+ for (i = 0; i < func_desc->cParams - pDispParams->cArgs; i++) {
+ int arglen = _argsize(func_desc->lprgelemdescParam[i].tdesc.vt);
+ TYPEDESC *tdesc = &(func_desc->lprgelemdescParam[i + pDispParams->cArgs].tdesc);
+ TYPEDESC i4_tdesc;
+ i4_tdesc.vt = VT_I4;
/* If we are a pointer to a variant, we are done already */
if ((tdesc->vt==VT_PTR)&&(tdesc->u.lptdesc->vt==VT_VARIANT))
@@ -4815,16 +4862,16 @@
TYPEATTR *tattr;
hres = ITypeInfo_GetRefTypeInfo(iface,tdesc->u.hreftype,&tinfo2);
- if (hres) {
+ if (FAILED(hres)) {
FIXME("Could not get typeinfo of hreftype %lx for VT_USERDEFINED, while coercing. Copying 4 byte.\n",tdesc->u.hreftype);
- return E_FAIL;
+ goto func_fail;
}
ITypeInfo_GetTypeAttr(tinfo2,&tattr);
switch (tattr->typekind) {
case TKIND_ENUM:
- /* force the return type to be VT_I4 */
- tdesc = &i4_tdesc;
- break;
+ /* force the return type to be VT_I4 */
+ tdesc = &i4_tdesc;
+ break;
case TKIND_ALIAS:
TRACE("TKIND_ALIAS to vt 0x%x\n",tattr->tdescAlias.vt);
tdesc = &(tattr->tdescAlias);
@@ -4859,57 +4906,67 @@
args2pos += arglen;
}
}
+func_fail:
+ HeapFree(GetProcessHeap(), 0, rgvarg);
HeapFree(GetProcessHeap(),0,args2);
HeapFree(GetProcessHeap(),0,args);
- return S_OK;
+ break;
}
case FUNC_DISPATCH: {
IDispatch *disp;
- HRESULT hr;
- hr = IUnknown_QueryInterface((LPUNKNOWN)pIUnk,&IID_IDispatch,(LPVOID*)&disp);
- if (hr) {
+ hres = IUnknown_QueryInterface((LPUNKNOWN)pIUnk,&IID_IDispatch,(LPVOID*)&disp);
+ if (SUCCEEDED(hres)) {
+ FIXME("Calling Invoke in IDispatch iface. untested!\n");
+ hres = IDispatch_Invoke(
+ disp,memid,&IID_NULL,LOCALE_USER_DEFAULT,dwFlags,pDispParams,
+ pVarResult,pExcepInfo,pArgErr
+ );
+ if (FAILED(hres))
+ FIXME("IDispatch::Invoke failed with %08lx. (Could be not a real error?)\n", hres);
+ IDispatch_Release(disp);
+ } else
FIXME("FUNC_DISPATCH used on object without IDispatch iface?\n");
- return hr;
- }
- FIXME("Calling Invoke in IDispatch iface. untested!\n");
- hr = IDispatch_Invoke(
- disp,memid,&IID_NULL,LOCALE_USER_DEFAULT,dwFlags,pDispParams,
- pVarResult,pExcepInfo,pArgErr
- );
- if (hr)
- FIXME("IDispatch::Invoke failed with %08lx. (Could be not a real error?)\n",hr);
- IDispatch_Release(disp);
- return hr;
+ break;
}
default:
- FIXME("Unknown function invocation type %d\n",pFDesc->funcdesc.funckind);
- return E_FAIL;
- }
- } else {
- for(pVDesc=This->varlist; pVDesc; pVDesc=pVDesc->next) {
- if (pVDesc->vardesc.memid == memid) {
- FIXME("varseek: Found memid name %s, but variable-based invoking not supported\n",debugstr_w(((LPWSTR)pVDesc->Name)));
- dump_TLBVarDesc(pVDesc);
- break;
- }
- }
+ FIXME("Unknown function invocation type %d\n", func_desc->funckind);
+ hres = E_FAIL;
+ break;
+ }
+
+ ITypeInfo2_ReleaseFuncDesc(iface, func_desc);
+ return hres;
+
+ } else if(SUCCEEDED(hres = ITypeInfo2_GetVarIndexOfMemId(iface, memid, &var_index))) {
+ VARDESC *var_desc;
+
+ hres = ITypeInfo2_GetVarDesc(iface, var_index, &var_desc);
+ if(FAILED(hres)) return hres;
+
+ FIXME("varseek: Found memid, but variable-based invoking not supported\n");
+ dump_VARDESC(var_desc);
+ ITypeInfo2_ReleaseVarDesc(iface, var_desc);
+ return E_NOTIMPL;
}
+
/* not found, look for it in inherited interfaces */
- if (This->TypeAttr.cImplTypes &&
- (This->TypeAttr.typekind==TKIND_INTERFACE || This->TypeAttr.typekind==TKIND_DISPATCH)) {
- /* recursive search */
- ITypeInfo *pTInfo;
- HRESULT hr;
- hr=ITypeInfo_GetRefTypeInfo(iface, This->impltypelist->hRef, &pTInfo);
- if(SUCCEEDED(hr)){
- hr=ITypeInfo_Invoke(pTInfo,pIUnk,memid,dwFlags,pDispParams,pVarResult,pExcepInfo,pArgErr);
- ITypeInfo_Release(pTInfo);
- return hr;
+ ITypeInfo2_GetTypeKind(iface, &type_kind);
+ if(type_kind == TKIND_INTERFACE || type_kind == TKIND_DISPATCH) {
+ HREFTYPE ref_type;
+ if(SUCCEEDED(ITypeInfo2_GetRefTypeOfImplType(iface, 0, &ref_type))) {
+ /* recursive search */
+ ITypeInfo *pTInfo;
+ hres = ITypeInfo_GetRefTypeInfo(iface, ref_type, &pTInfo);
+ if(SUCCEEDED(hres)){
+ hres = ITypeInfo_Invoke(pTInfo,pIUnk,memid,dwFlags,pDispParams,pVarResult,pExcepInfo,pArgErr);
+ ITypeInfo_Release(pTInfo);
+ return hres;
+ }
+ WARN("Could not search inherited interface!\n");
}
- WARN("Could not search inherited interface!\n");
}
- ERR("did not find member id %d, flags %d!\n", (int)memid, dwFlags);
+ ERR("did not find member id %08lx, flags %d!\n", memid, dwFlags);
return DISP_E_MEMBERNOTFOUND;
}
@@ -5176,6 +5233,9 @@
{
ITypeInfoImpl *This = (ITypeInfoImpl *)iface;
TRACE("(%p)->(%p)\n", This, pTypeAttr);
+ if(This->TypeAttr.typekind == TKIND_ALIAS)
+ free_deep_typedesc(&pTypeAttr->tdescAlias);
+ HeapFree(GetProcessHeap(), 0, pTypeAttr);
}
/* ITypeInfo::ReleaseFuncDesc
@@ -5242,18 +5302,18 @@
TLBFuncDesc *pFuncInfo;
int i;
HRESULT result;
- /* FIXME: should check for invKind??? */
- for(i=0, pFuncInfo=This->funclist;pFuncInfo &&
- memid != pFuncInfo->funcdesc.memid; i++, pFuncInfo=pFuncInfo->next);
- if(pFuncInfo){
- *pFuncIndex=i;
- result= S_OK;
- }else{
- *pFuncIndex=0;
- result=E_INVALIDARG;
- }
+
+ for(i = 0, pFuncInfo = This->funclist; pFuncInfo; i++, pFuncInfo=pFuncInfo->next)
+ if(memid == pFuncInfo->funcdesc.memid && (invKind & pFuncInfo->funcdesc.invkind))
+ break;
+ if(pFuncInfo) {
+ *pFuncIndex = i;
+ result = S_OK;
+ } else
+ result = TYPE_E_ELEMENTNOTFOUND;
+
TRACE("(%p) memid 0x%08lx invKind 0x%04x -> %s\n", This,
- memid, invKind, SUCCEEDED(result)? "SUCCES":"FAILED");
+ memid, invKind, SUCCEEDED(result) ? "SUCCESS" : "FAILED");
return result;
}
@@ -5273,15 +5333,14 @@
for(i=0, pVarInfo=This->varlist; pVarInfo &&
memid != pVarInfo->vardesc.memid; i++, pVarInfo=pVarInfo->next)
;
- if(pVarInfo){
- *pVarIndex=i;
- result= S_OK;
- }else{
- *pVarIndex=0;
- result=E_INVALIDARG;
- }
+ if(pVarInfo) {
+ *pVarIndex = i;
+ result = S_OK;
+ } else
+ result = TYPE_E_ELEMENTNOTFOUND;
+
TRACE("(%p) memid 0x%08lx -> %s\n", This,
- memid, SUCCEEDED(result)? "SUCCES":"FAILED");
+ memid, SUCCEEDED(result) ? "SUCCESS" : "FAILED");
return result;
}
--- trunk/reactos/lib/oleaut32/typelib2.c 2005-01-12 19:51:26 UTC (rev 12986)
+++ trunk/reactos/lib/oleaut32/typelib2.c 2005-01-12 19:51:40 UTC (rev 12987)
@@ -48,10 +48,8 @@
#include "wine/unicode.h"
#include "objbase.h"
-#include "ole2disp.h"
#include "typelib.h"
#include "wine/debug.h"
-#include "variant.h"
WINE_DEFAULT_DEBUG_CHANNEL(typelib2);
/* WINE_DEFAULT_DEBUG_CHANNEL(ole); */
@@ -150,7 +148,7 @@
ICreateTypeLib2Vtbl *lpVtbl;
ITypeLib2Vtbl *lpVtblTypeLib2;
- UINT ref;
+ ULONG ref;
WCHAR *filename;
@@ -176,7 +174,7 @@
ICreateTypeInfo2Vtbl *lpVtbl;
ITypeInfo2Vtbl *lpVtblTypeInfo2;
- UINT ref;
+ ULONG ref;
ICreateTypeLib2Impl *typelib;
MSFT_TypeInfoBase *typeinfo;
@@ -979,18 +977,25 @@
break;
case VT_CARRAY:
+ {
/* FIXME: Make with the error checking. */
- FIXME("Array vartype, hacking badly.\n");
+ int num_dims = tdesc->u.lpadesc->cDims, elements = 1, dim;
ctl2_encode_typedesc(This, &tdesc->u.lpadesc->tdescElem, &target_type, width, alignment, NULL);
- arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, 16, 0);
+ arrayoffset = ctl2_alloc_segment(This, MSFT_SEG_ARRAYDESC, (2 + 2 * num_dims) * sizeof(int), 0);
arraydata = (void *)&This->typelib_segment_data[MSFT_SEG_ARRAYDESC][arrayoffset];
arraydata[0] = target_type;
- arraydata[1] = 0x00080001;
- arraydata[2] = 0x8;
- arraydata[3] = 0;
+ arraydata[1] = num_dims;
+ arraydata[1] |= ((num_dims * 2 * sizeof(int)) << 16);
+ arraydata += 2;
+ for(dim = 0; dim < num_dims; dim++) {
+ arraydata[0] = tdesc->u.lpadesc->rgbounds[dim].cElements;
+ arraydata[1] = tdesc->u.lpadesc->rgbounds[dim].lLbound;
+ elements *= tdesc->u.lpadesc->rgbounds[dim].cElements;
+ arraydata += 2;
+ }
typeoffset = ctl2_alloc_segment(This, MSFT_SEG_TYPEDESC, 8, 0);
typedata = (void *)&This->typelib_segment_data[MSFT_SEG_TYPEDESC][typeoffset];
@@ -998,12 +1003,11 @@
typedata[1] = arrayoffset;
*encoded_tdesc = typeoffset;
- *width = 8;
- *alignment = 1;
- *decoded_size = sizeof(ARRAYDESC);
+ *width = *width * elements;
+ *decoded_size = sizeof(ARRAYDESC) + (num_dims - 1) * sizeof(SAFEARRAYBOUND);
break;
-
+ }
case VT_USERDEFINED:
TRACE("USERDEFINED.\n");
for (typeoffset = 0; typeoffset < This->typelib_segdir[MSFT_SEG_TYPEDESC].length; typeoffset += 8) {
@@ -1138,10 +1142,11 @@
static ULONG WINAPI ICreateTypeInfo2_fnAddRef(ICreateTypeInfo2 *iface)
{
ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
+ ULONG ref = InterlockedIncrement(&This->ref);
- TRACE("(%p)->ref was %u\n",This, This->ref);
+ TRACE("(%p)->ref was %lu\n",This, ref - 1);
- return ++(This->ref);
+ return ref;
}
/******************************************************************************
@@ -1152,12 +1157,11 @@
static ULONG WINAPI ICreateTypeInfo2_fnRelease(ICreateTypeInfo2 *iface)
{
ICreateTypeInfo2Impl *This = (ICreateTypeInfo2Impl *)iface;
+ ULONG ref = InterlockedDecrement(&This->ref);
- --(This->ref);
+ TRACE("(%p)->(%lu)\n",This, ref);
- TRACE("(%p)->(%u)\n",This, This->ref);
-
- if (!This->ref) {
+ if (!ref) {
if (This->typelib) {
ICreateTypeLib2_fnRelease((ICreateTypeLib2 *)This->typelib);
This->typelib = NULL;
@@ -1168,7 +1172,7 @@
return 0;
}
- return This->ref;
+ return ref;
}
@@ -3005,10 +3009,11 @@
static ULONG WINAPI ICreateTypeLib2_fnAddRef(ICreateTypeLib2 *iface)
{
ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
+ ULONG ref = InterlockedIncrement(&This->ref);
- TRACE("(%p)->ref was %u\n",This, This->ref);
+ TRACE("(%p)->ref was %lu\n",This, ref - 1);
- return ++(This->ref);
+ return ref;
}
/******************************************************************************
@@ -3019,30 +3024,25 @@
static ULONG WINAPI ICreateTypeLib2_fnRelease(ICreateTypeLib2 *iface)
{
ICreateTypeLib2Impl *This = (ICreateTypeLib2Impl *)iface;
+ ULONG ref = InterlockedDecrement(&This->ref);
- --(This->ref);
+ TRACE("(%p)->(%lu)\n",This, ref);
- TRACE("(%p)->(%u)\n",This, This->ref);
-
- if (!This->ref) {
+ if (!ref) {
int i;
for (i = 0; i < MSFT_SEG_MAX; i++) {
- if (This->typelib_segment_data[i]) {
- HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
- This->typelib_segment_data[i] = NULL;
- }
+ HeapFree(GetProcessHeap(), 0, This->typelib_segment_data[i]);
+ This->typelib_segment_data[i] = NULL;
}
- if (This->filename) {
- HeapFree(GetProcessHeap(), 0, This->filename);
- This->filename = NULL;
- }
+ HeapFree(GetProcessHeap(), 0, This->filename);
+ This->filename = NULL;
while (This->typeinfos) {
ICreateTypeInfo2Impl *typeinfo = This->typeinfos;
This->typeinfos = typeinfo->next_typeinfo;
- if (typeinfo->typedata) HeapFree(GetProcessHeap(), 0, typeinfo->typedata);
+ HeapFree(GetProcessHeap(), 0, typeinfo->typedata);
HeapFree(GetProcessHeap(), 0, typeinfo);
}
@@ -3050,7 +3050,7 @@
return 0;
}
- return This->ref;
+ return ref;
}