确定对象的类名

确定对象的类名
; 示例: 确定对象的类名.

obj := ComObjCreate("Scripting.Dictionary")

MsgBox % "Interface name: " ComObjType(obj, "name")

IID_IProvideClassInfo := "{B196B283-BAB4-101A-B69C-00AA00341D07}"

; 请求到对象的 IProvideClassInfo 接口的指针.
if !(pci := ComObjQuery(obj, IID_IProvideClassInfo))
{
    MsgBox IProvideClassInfo interface not supported.
    return
}

; 调用 GetClassInfo 来获取到 ITypeInfo 接口的指针.
DllCall(vtable(pci, 3), "ptr", pci, "ptr*", ti)

; 调用 GetDocumentation 来获取对象的完整类型名称.
DllCall(vtable(ti, 12), "ptr", ti, "int", -1, "ptr*", name, "ptr", 0, "ptr", 0, "ptr", 0)

; 转换 BSTR 指针为可用的字符串.
name := StrGet(name, "UTF-16")

; 释放原始接口指针.
ObjRelease(ti)
ObjRelease(pci)

; 显示类型名称!
MsgBox % "Class name: " name

vtable(ptr, n) {
    ; NumGet(ptr+0) 返回对象的虚函数表
    ; (简称为 vtable) 的地址. 表达式的其余部分从
    ; vtable 获取第 n 个函数的地址.
    return NumGet(NumGet(ptr+0), n*A_PtrSize)
}

 

给TA捐赠
共{{data.count}}人
人已捐赠
其他

[视频工具]绿色视频编辑工具camtasia studio9.1下载

2018-1-2 17:06:47

其他

自动化已有的Internet Explorer窗口

2018-1-3 8:46:54

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索