我有一个ActiveX / COM DLL。它包含了许多方法和属性。我想能够问它,如果它具有特定的符号,按照下面的代码片断:

If HasMethod( "StdLib.DLL", "ReadFileE" ) Then
    ...
End If

时有没有办法,比如说,从VBScript或JScript做到这一点?如果不是这样,我在哪里去得到我需要的信息?

有帮助吗?

解决方案

谷歌搜索周围不太找到我想要的东西后,我想起了 Edanmo 网站这让我想起了TLBINF32.DLL,下载微软的 TLBINF32.CHM 和阅读了上GetMembersWithSubStringEx。下面是它的实现(VB6做一起TLBINF32.DLL参考),一些演示VBScript和输出,以及在一些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

的VBScript演示。上面的代码被包含在我STDLIB DLL在注册表共类。

Dim O, R
Set O = CreateObject("Std.Registry")
Set R = CreateObject("Std.Arrays")
WScript.Echo R.ShowStructure( O.SearchTLIMethodsAndProperties( "MSSCRIPT.OCX",""))

从演示输出(脚本是在赛特运行)。

>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

最后,VBA代码。小区中有一个符号和这个程序发现它或者返回一个错误串。

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

回过头来看现在,我想我可能传递的路径,DLL / OCX作为第一个参数。

其他提示

我已经使用微软的交互式OLE / COM-对象观众找到mehods及其参数在的ActiveX-的DLL。也许看着观众的源代码将导致你在正确的方向:的 MSDN OLEVIEW样品

如果你想以编程方式做到这一点 - 我不知道的简单的方式来做到这一点。无论如何,如果你真的需要(如果你的编程语言是有足够的能力) - 可以查询类型库(指的ITypeLib描述某处的 http://msdn.microsoft.com/en-us/library/ms221549.aspx )。

另外,如果你已经有了一个IDispatch指针 - 你可以考虑使用其服务,以动态地枚举接口支持的方法(参考MSDN的IDispatch的描述)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top