MCPcopy Create free account
hub / github.com/WinMerge/winmerge / GetFunctionsFromScript

Function GetFunctionsFromScript

Src/Plugins.cpp:105–154  ·  view source on GitHub ↗

list the function IDs and names in a script or activeX dll

Source from the content-addressed store, hash-verified

103
104// list the function IDs and names in a script or activeX dll
105int GetFunctionsFromScript(IDispatch *piDispatch, vector<String>& namesArray, vector<int>& IdArray, INVOKEKIND wantedKind)
106{
107 UINT iValidFunc = 0;
108 if (piDispatch != nullptr)
109 {
110 ITypeInfo *piTypeInfo=nullptr;
111 unsigned iTInfo = 0; // 0 for type information of IDispatch itself
112 LCID lcid=0; // locale for localized method names (ignore if no localized names)
113 if (SUCCEEDED(piDispatch->GetTypeInfo(iTInfo, lcid, &piTypeInfo)))
114 {
115 TYPEATTR *pTypeAttr=nullptr;
116 if (SUCCEEDED(piTypeInfo->GetTypeAttr(&pTypeAttr)))
117 {
118 // allocate arrays for the returned structures
119 // the names array is NUL terminated
120 namesArray.resize(pTypeAttr->cFuncs+1);
121 IdArray.resize(pTypeAttr->cFuncs+1);
122
123 UINT iMaxFunc = pTypeAttr->cFuncs - 1;
124 for (UINT iFunc = 0 ; iFunc <= iMaxFunc ; ++iFunc)
125 {
126 UINT iFuncDesc = iMaxFunc - iFunc;
127 FUNCDESC *pFuncDesc;
128 if (SUCCEEDED(piTypeInfo->GetFuncDesc(iFuncDesc, &pFuncDesc)))
129 {
130 // exclude properties
131 // exclude IDispatch inherited methods
132 if (pFuncDesc->invkind & wantedKind && !(pFuncDesc->wFuncFlags & 1))
133 {
134 BSTR bstrName;
135 UINT cNames;
136 if (SUCCEEDED(piTypeInfo->GetNames(pFuncDesc->memid,
137 &bstrName, 1, &cNames)))
138 {
139 IdArray[iValidFunc] = pFuncDesc->memid;
140 namesArray[iValidFunc] = ucr::toTString(bstrName);
141 iValidFunc ++;
142 }
143 SysFreeString(bstrName);
144 }
145 piTypeInfo->ReleaseFuncDesc(pFuncDesc);
146 }
147 }
148 piTypeInfo->ReleaseTypeAttr(pTypeAttr);
149 }
150 piTypeInfo->Release();
151 }
152 }
153 return iValidFunc;
154}
155
156int GetMethodsFromScript(IDispatch *piDispatch, vector<String>& namesArray, vector<int> &IdArray)
157{

Callers 2

GetMethodsFromScriptFunction · 0.85

Calls 10

SUCCEEDEDFunction · 0.85
toTStringFunction · 0.85
GetTypeAttrMethod · 0.80
GetFuncDescMethod · 0.80
GetNamesMethod · 0.80
ReleaseFuncDescMethod · 0.80
ReleaseTypeAttrMethod · 0.80
GetTypeInfoMethod · 0.45
resizeMethod · 0.45
ReleaseMethod · 0.45

Tested by

no test coverage detected