How do I search for an ActiveX / COM object for a method?
I have an ActiveX / COM DLL. It contains many methods and properties. I would like to be able to ask him if he has a specific character according to the following snippet:
If HasMethod( "StdLib.DLL", "ReadFileE" ) Then
...
End If
Is there a way to do this with, for example, VBScript or JScript? If not, where should I go to get the information I need?
a source to share
After Google didn't find what I wanted, I remembered the Edanmo site , which got me thinking about TLBINF32.DLL by downloading Microsoft's TLBINF32.CHM and reading on GetMembersWithSubStringEx. Below is its implementation (made in VB6 with reference to TLBINF32.DLL), some demo VBScript, and output and wrapping this functionality in some VBA.
Public Function SearchTLIMethodsAndProperties(sTypelib As Variant, sSymbol As Variant) As Variant
Dim SI As SearchItem
Dim aResults As Variant
Dim bFound as boolean
Dim Groups(1) As InvokeKinds
Groups(0) = INVOKE_FUNC Or INVOKE_PROPERTYGET Or _
INVOKE_PROPERTYPUT Or INVOKE_PROPERTYPUTREF
ReDim aResults(0)
bFound = False
With TypeLibInfoFromFile(sTypelib)
.SearchDefault = tliStClasses Or tliStEvents
For Each SI In .GetMembersWithSubStringEx(sSymbol, Groups)
bFound = True
arr.AAdd_PostIncrement aResults, SI.Name
Next
End With
if bFound then
ReDim Preserve aResults(UBound(aResults) - 1)
end if
SearchTLIMethodsAndProperties = aResults
End Function
Demo version of VBScript. The above code was included in my StdLib DLL in a composite registry class.
Dim O, R
Set O = CreateObject("Std.Registry")
Set R = CreateObject("Std.Arrays")
WScript.Echo R.ShowStructure( O.SearchTLIMethodsAndProperties( "MSSCRIPT.OCX",""))
Exit demo (script was run in SciTE).
>cscript "C:\foo\foo.vbs"
{Add,AddCode,AddObject,AllowUI,Clear,CodeObject,Column,Count,Description,Error,Eval,ExecuteStatement,HasReturnValue,HelpContext,HelpFile,Item,Language,Line,Modules,Name,NumArgs,Number,Procedures,Reset,Run,SitehWnd,Source,State,Text,Timeout,UseSafeSubset}
>Exit code: 0
Finally, the VBA code. The cell has a character in it, and this procedure finds or returns an error string.
Public Function LookupSymbol(sSym As String) As String
Dim aRes As Variant
aRes = reg.SearchTLIMethodsAndProperties("MSSCRIPT.OCX", sSym)
Dim i As Integer
LookupSymbol = "!!NotFound!!"
For i = 0 To UBound(aRes)
If LCase$(aRes(i)) = LCase$(sSym) Then
LookupSymbol = sSym
Exit For
End If
Next
End Function
In hindsight, I think that I could go to the DLL / OCX path as the first parameter.
a source to share
I used Microsofts' interactive OLE / COM Object Viewer to find mehods and their parameters in an ActiveX DLL. Perhaps looking at the viewer's source code will lead you in the right direction: MSDN OleView Example
a source to share
If you want to do it programmatically, I don't know of an easy way to do it. Anyway, if you really need to (and if your programming language is large enough), you can request a type library (see the ITypeLib description somewhere at http://msdn.microsoft.com/en-us/library/ms221549. aspx ).
Additionally, if you already have an IDispatch pointer, you can use its services to dynamically enumerate the methods supported by the interface (see the description for IDispatch on MSDN).
a source to share