使用动态转储 ComObject 对象?
我正在尝试(不幸的是)为我在 Office 类型库中访问的对象实现“对象转储器”。
肯定有可能,因为 VS 的调试窗口有一个 System.__ComObject 对象的“动态视图”,它可以有效地完成我想要的操作。
有什么想法吗?
I'm trying (without luck) to implement an "Object Dumper" for objects I'm accessing in the Office Type Library.
It must be possibly, because VS's debug window has a "dynamic view" for the System.__ComObject objects that effectively does what I want.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还创建了一个方法来获取可用于访问对象的接口。使用:
您的代码中必须有一个 IDispatch 接口:
我的方法将 COM 对象转换为 IDispatch,获取非托管类型信息,从非公共 Marshal 方法 GetTypeInfoGuid 获取对象类型 GUID,然后在当前 AppDomain 的程序集中搜索它。
如果未找到适当的类型,该方法将返回 System.__ComObject 类型。但是,您可以从中获取 GUID 属性值,因此至少您将获得 GUID。
用法:
希望这会有所帮助。祝你好运。 ☺
编辑:
找到了一个更简单但速度较慢的方法:
I have also created a method for getting an interface that can be used for accessing the object. Use:
You have to have an IDispatch interface in your code:
My method casts COM object to IDispatch, gains unmanaged type info, gets object type GUID from non-public Marshal method GetTypeInfoGuid and then searchs it in current AppDomain's assemblies.
If the appropriate type isn't found, the method will return type of System.__ComObject. However, you can get GUID property value from it, so at least you will get the GUID.
Usage:
Hope this helps. Good luck. ☺
Edit:
Found an easier but slower method: