HRESULT CJSProxyObj::SetEventNames() { ITypeInfo* pInfo; if (m_pTypeInfo == nullptr) pInfo = theApp.m_pEventTypeInfo.p; else pInfo = m_pTypeInfo.p; TYPEATTR *pta = nullptr;; HRESULT hr = pInfo->GetTypeAttr(&pta); if (FAILED(hr)) return hr; BSTR bstrName = ::SysAllocString(L""); FUNCDESC *pfd = nullptr; unsigned int uiNames = 0; for (int i = 0; i < pta->cFuncs; i++) { hr = pInfo->GetFuncDesc(i, &pfd); if (FAILED(hr)) continue; hr = pInfo->GetNames(pfd->memid, &bstrName, 1, &uiNames); if (SUCCEEDED(hr) && bstrName && SysStringLen(bstrName)) { m_mapDispId.Add(pfd->memid, bstrName); ATLTRACE(_T("*********Add function '%s' in Tangram*******\r\n"), OLE2T(bstrName)); } pInfo->ReleaseFuncDesc(pfd); pfd = nullptr; } pInfo->ReleaseTypeAttr(pta); return hr; }
JNIEXPORT jobjectArray JNICALL Java_org_racob_com_TypeInfo_getNames (JNIEnv *env, jobject obj, jint pointer, jint memid) { ITypeInfo *typeInfo = (ITypeInfo *) pointer; BSTR names[MAX_NAMES]; unsigned int namesCount; HRESULT hr = typeInfo->GetNames(memid, names, MAX_NAMES, &namesCount); if (!SUCCEEDED(hr)) { ThrowComFail(env, "getNames failed", hr); return NULL; } // Make primitive String array for names jclass autoClass = env->FindClass("java/lang/String"); jobjectArray array = env->NewObjectArray(namesCount, autoClass, NULL); if (!SUCCEEDED(hr)) { ThrowComFail(env, "getNames failed to make return array", hr); return NULL; } // Fill up array for (unsigned int i = 0; i < namesCount; i++) { int len = SysStringLen(names[i]); jstring string = env->NewString((const jchar *) names[i], len); env->SetObjectArrayElement(array, i, string); SysFreeString(names[i]); } return array; }
int Sorter::compare( VARIANT * elem_1, VARIANT * elem_2 ) { HRESULT hr; if( this->p_Compare != NULL ) { DISPPARAMS dargs = { NULL, NULL, 0, 0 }; VARIANT vresult; VariantInit(&vresult); DISPID dp[1]; LPOLESTR name = L"callback_compare"; hr = p_Compare->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_SYSTEM_DEFAULT, dp); // dp[0] contains id , not id=1 as specified in the IDL hr = p_Compare->Invoke( dp[0], IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dargs, &vresult, NULL, NULL); // nothing happens? // other things I have tried: name = L"QueryInterface"; hr = p_Compare->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_SYSTEM_DEFAULT, dp); // returns: E_UNKNOWN_NAME - why? ITypeInfo * pIT; hr = p_Compare->GetTypeInfo( NULL, LOCALE_SYSTEM_DEFAULT, &pIT ); UINT cNames = 0; LPOLESTR rgszNames[1]; hr = pIT->GetNames( dp[0], rgszNames, 1, &cNames); // rgszNames contians mysorter_callback_compare, the vba implementation hr = S_OK; } return 0; }
void CAutoListMembersWindow::SetDispatch(IDispatch* pDisp) { ClearMemberItems(); UINT pctinfo; pDisp->GetTypeInfoCount(&pctinfo); ITypeInfo* pTInfo; HRESULT hr = pDisp->GetTypeInfo(0, NULL, &pTInfo); TYPEATTR* pType; pTInfo->GetTypeAttr(&pType); for (int i = 0; i < pType->cFuncs; i++) { FUNCDESC* pFuncDesc = NULL; if (SUCCEEDED(pTInfo->GetFuncDesc(i, &pFuncDesc))) { BSTR bname; UINT pcNames; pTInfo->GetNames(pFuncDesc->memid, &bname, 1, &pcNames); CMemberItem* pMItem = new CMemberItem; pMItem->m_name = _bstr_t(bname, false); pMItem->m_dispid = pFuncDesc->memid; if (pFuncDesc->invkind == DISPATCH_METHOD) { pMItem->m_type = 1; } else/* if (pFuncDesc->invkind == INVOKE_PROPERTYPUT || pFuncDesc->invkind == INVOKE_PROPERTYGET || pFuncDesc->invkind == INVOKE_PROPERTYPUTREF*/ { pMItem->m_type = 0; } m_members.Add(pMItem); pTInfo->ReleaseFuncDesc(pFuncDesc); } } if (m_hWnd) { OnSize(); Invalidate(); } }
JNIEXPORT jobject JNICALL Java_org_racob_com_TypeInfo_getFuncDesc (JNIEnv *env, jobject obj, jint pointer, jint index) { ITypeInfo *typeInfo = (ITypeInfo *) pointer; if (!typeInfo) return NULL; FUNCDESC *funcDesc = NULL; HRESULT hr = typeInfo->GetFuncDesc(index, &funcDesc); if (!SUCCEEDED(hr)) { ThrowComFail(env, "getFuncDesc failed", hr); return NULL; } int paramLength = funcDesc->cParams; unsigned int nameLength = 0; BSTR *names = (BSTR *) malloc(sizeof(BSTR) * paramLength + 1); hr = typeInfo->GetNames(funcDesc->memid, names, paramLength + 1, &nameLength); if (FAILED(hr)) { typeInfo->ReleaseFuncDesc(funcDesc); ThrowComFail(env, "getFuncDesc failed", hr); return NULL; } SysFreeString(names[0]); jclass paramClass = env->FindClass("org/racob/com/Parameter"); jmethodID paramCons = env->GetMethodID(paramClass, "<init>", "(Ljava/lang/String;ZZZZIZLorg/racob/com/Variant;)V"); jobjectArray parameters = env->NewObjectArray(nameLength - 1, paramClass, 0); for (int i = 0; i < nameLength - 1; i++) { jobject parameter = createParameter(env, paramClass, paramCons, funcDesc->lprgelemdescParam[i], names[i+1]); env->SetObjectArrayElement(parameters, i, parameter); env->DeleteLocalRef(parameter); } jobject returnValue = createParameter(env, paramClass, paramCons, funcDesc->elemdescFunc, NULL); jclass autoClass = env->FindClass("org/racob/com/FuncDesc"); jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(IIII[Lorg/racob/com/Parameter;Lorg/racob/com/Parameter;II)V"); jobject newAuto = env->NewObject(autoClass, autoCons, funcDesc->memid, index, funcDesc->invkind, funcDesc->wFuncFlags, parameters, returnValue, funcDesc->cParamsOpt, funcDesc->oVft); typeInfo->ReleaseFuncDesc(funcDesc); return newAuto; }
/**********88 PyObject *PyITypeInfo::GetIDsOfNames(OLECHAR FAR* FAR* names, int count) { ITypeInfo *pMyTypeInfo = GetI(this); if (pMyTypeInfo==NULL) return NULL; MEMBERID *ids = new MEMBERID[count]; SCODE sc = pMyTypeInfo->GetIDsOfNames(names, count, ids); if (FAILED(sc)) { delete [] ids; return PyCom_BuildPyException(sc, pMyTypeInfo, IID_ITypeInfo); } PyObject *ret = PyTuple_New(count); for (int i = 0; i < count; i++) PyTuple_SetItem(ret, i, PyInt_FromLong(ids[i])); delete [] ids; return ret; } **********/ PyObject *PyITypeInfo::GetNames(MEMBERID id) { BSTR names[256]; unsigned len = 0; ITypeInfo *pMyTypeInfo = GetI(this); if (pMyTypeInfo==NULL) return NULL; PY_INTERFACE_PRECALL; SCODE sc = pMyTypeInfo->GetNames(id, names, 256, &len); PY_INTERFACE_POSTCALL; if (FAILED(sc)) return PyCom_BuildPyException(sc, pMyTypeInfo, IID_ITypeInfo); PyObject *ret = PyTuple_New(len); for (unsigned i = 0; i < len; i++) { // Again, MAkeBSTRToObj occasionally gives crap at EOS. PyObject *obString = MakeOLECHARToObj(names[i]); PyTuple_SetItem(ret, i, obString); SysFreeString(names[i]); } return ret; }
BOOL comauto::RecordInfo::IsMatchingType( IRecordInfo *pRecordInfo) { BOOL rt = TRUE; ITypeInfo* otypeinfo = 0; ITypeInfo* rectypeinfo = 0; ITypeInfo* orectypeinfo = 0; TYPEATTR* otypeattr = 0; VARDESC* vd = 0; VARDESC* ovd = 0; BSTR varname = NULL; BSTR ovarname = NULL; try { WRAP( pRecordInfo->GetTypeInfo( &otypeinfo)) WRAP( otypeinfo->GetTypeAttr( &otypeattr)) if (m_typeattr->guid == otypeattr->guid) goto Cleanup; if (m_typeattr->cVars != otypeattr->cVars) {rt=FALSE; goto Cleanup;} unsigned short ii; for (ii = 0; ii < m_typeattr->cVars; ++ii) { if (vd) { m_typeinfo->ReleaseVarDesc( vd); vd = NULL; } WRAP( m_typeinfo->GetVarDesc( ii, &vd)) if (ovd) { otypeinfo->ReleaseVarDesc( ovd); ovd = NULL; } WRAP( otypeinfo->GetVarDesc( ii, &ovd)) if (vd->elemdescVar.tdesc.vt != ovd->elemdescVar.tdesc.vt || vd->oInst != ovd->oInst) { rt=FALSE; goto Cleanup; } UINT nn; if (varname) { ::SysFreeString( varname); varname = NULL; } WRAP( m_typeinfo->GetNames( vd->memid, &varname, 1, &nn)) if (ovarname) { ::SysFreeString( ovarname); ovarname = NULL; } WRAP( otypeinfo->GetNames( ovd->memid, &ovarname, 1, &nn)) if (wcscmp( varname, ovarname) != 0) { rt=FALSE; goto Cleanup; } if (vd->elemdescVar.tdesc.vt == VT_USERDEFINED) { if (rectypeinfo) { rectypeinfo->Release(); rectypeinfo = 0; } WRAP( m_typeinfo->GetRefTypeInfo( vd->elemdescVar.tdesc.hreftype, &rectypeinfo)) if (orectypeinfo) { orectypeinfo->Release(); orectypeinfo = NULL; } WRAP( m_typeinfo->GetRefTypeInfo( ovd->elemdescVar.tdesc.hreftype, &orectypeinfo)) comauto::RecordInfo rec( rectypeinfo); comauto::RecordInfo orec( orectypeinfo); if (rec.IsMatchingType( &orec) == FALSE) { rt=FALSE; goto Cleanup; } } } } catch (...) { rt = FALSE; } Cleanup: if (vd) m_typeinfo->ReleaseVarDesc( vd); if (ovd) otypeinfo->ReleaseVarDesc( ovd); if (otypeattr) otypeinfo->ReleaseTypeAttr( otypeattr); if (rectypeinfo) rectypeinfo->Release(); if (orectypeinfo) orectypeinfo->Release(); if (otypeinfo) otypeinfo->Release(); if (varname) ::SysFreeString( varname); if (ovarname) ::SysFreeString( ovarname); return rt; }
STDMETHODIMP ESource::InitEvent(IDispatch *SourceDispatch, OrxScript *ORexxScript, FILE *LogFile) { ITypeInfo *SourceType; TYPEATTR *TypeAttributes; BSTR SourceName; unsigned int NameCount; int i; FUNCDESC *FuncDesc; char DispIDName[29]; PEMAP NewMap; HRESULT RetCode=S_OK; int EMCount; FPRINTF2(LogFile,"created a new Event Source. %p\n",this); FPRINTF2(DLLlogfile,"created a new Event Source.%p\n",this); EventType = AddScriptlet; Source = SourceDispatch; // Mimick the ParseProcedures "THIS" parameter by returning this pointer. Engine = ORexxScript; Connected = false; ConnectionPoint = NULL; Container = NULL; logfile = LogFile; RetCode = GetTypeInfo(&SourceType); if (SUCCEEDED(RetCode)) { RetCode = SourceType->GetTypeAttr(&TypeAttributes); memcpy(&SourceGUID,&TypeAttributes->guid,sizeof(GUID)); EMCount = TypeAttributes->cFuncs; SourceType->ReleaseTypeAttr(TypeAttributes); OLECHAR lGUID[50]; StringFromGUID2(SourceGUID,lGUID,sizeof(lGUID)); FPRINTF2(logfile,"The GUID is %S and there are %d functions.\n",lGUID,EMCount); /* For each entry in the type library, create an entry on the Event Map chain. * This is a many to one relation. Each of the different Source Disp ID's * will translate to the same Sink Disp ID. There is only one chunk of code * being bound to this Event that the Type Library is describing. So every * Source call must map to the same Sink. */ for (i=0; i<EMCount; i++) { SourceType->GetFuncDesc(i, &FuncDesc); // Despite what the documentation says, this returns Max Names, not Max Names - 1. // The first name is the function name, the remainder if they exist are parameters. SourceType->GetNames(FuncDesc->memid, &SourceName, 1, &NameCount); sprintf(DispIDName,"%d",FuncDesc->memid); // This creates the entry for the function with an invalid DispID to call. RetCode = AddMap(DispIDName,&NewMap); if (FAILED(RetCode)) return RetCode; FPRINTF2(logfile,"ESource::InitEvent - AddScriptlet \"%S\" \n",SourceName); NewMap->SourceEventName = SourceName; SourceType->ReleaseFuncDesc(FuncDesc); } SourceType->Release(); } else { FPRINTF2(logfile,"Could not obtain TypInfo for this event! HRESULT %08x\n",RetCode); } return RetCode; }