如何在 Perl 中以编程方式发现 Win32::OLE 对象的属性和方法?
对于 Perl,使用 Win32::OLE
库来加载非常容易建立 COM/OLE 对象并控制它们。我遇到的问题是确切地知道我正在访问的对象中有哪些方法和属性可用。其他语言的某些 OLE 工具包可以通过读取对象上可用的所有属性和方法来为您生成静态接口。 Perl 的 Win32::OLE 库中是否存在这样的功能?
With Perl, it's quite easy using the Win32::OLE
library to load up COM/OLE objects and control them. The issue I'm running into is knowing exactly what methods and properties are available in the object I'm accessing. Some OLE toolkits in other languages can generate a static interface for you by reading all of the properties and methods that are available on the object. Does such a facility exist with Perl's Win32::OLE
library?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该直接从
Win32::OLE
对象的键访问属性。我们以 Excel 为例。代码来自 Win32::OLE 示例 -properties.pl它将显示
Win32::OLE
对象的所有属性。在一行中,要获取 Win32::OLE 对象的所有属性:
可以通过
Win32::OLE::TypeInfo
检索所有 OLE 方法。此代码块将打印 $OleObject 的所有方法名称:You should access the properties from the
Win32::OLE
object's keys directly. Let's use Excel as the example. The code is from Win32::OLE examples - properties.plIt will show all properties of an
Win32::OLE
object.In one line, to get all properties of a Win32::OLE object:
All OLE methods can be retrieved via
Win32::OLE::TypeInfo
. this block of code will print all the method names of $OleObject:有一点是肯定的,如果你这样做:
你很可能只会陷入无限循环。但你可以这样修改它:
然后你至少可以看到属性名称。要查看其下一个级别的值,您需要
Maxdepth=3
。我不太确定如何查看文档以外的所有方法。One thing is for sure, if you do this:
you'll likely only get an endless loop. But you can modify it like this:
And then you can at least see the property names. To see their next level of values, you will need
Maxdepth=3
. I'm not exactly sure how to look at all the methods other than documentation.不,但看起来必要的类型发现代码 已经在 Win32 中::OLE 的实现。您可以使用它作为参考来编写自己的 Perl 扩展,该扩展公开函数和方法的类型和名称。
No. but it looks like the necessary type discovery code is already in Win32::OLE's implementation. You can use it as a reference to write your own perl extension that exposes function and method types and names.
如果您使用 ActiveState,则包含 OLE 浏览器(可在“开始”菜单中找到)。它要求您启用“本地 Intranet”区域的“初始化和脚本未标记为安全的 ActiveX 控件” 安全设置,但通常它运行良好,并为您提供以下列表:所有属性和方法及其类型。
另一个好的来源是各个应用程序中的文档 - MS 应用程序通常附带 VBA 文档。请注意,这些应用程序中描述的对象模型与 OLE 链接相同。
If you are using ActiveState, there is OLE Browser included (available in Start menu). It requires you to enable "Initialize and script ActiveX controls not marked as safe" security setting of the "Local intranet" zone, but generally it works well and gives you list of all properties and methods along with its types.
Another good source is documentation in individual applications - MS applications usually come with VBA docs. Note that object model described in those apps is the same OLE links to.