初始化 COM 对象时类型不匹配
我有一个调用 C# COM dll 的 Excel VBA 模块。
有时,当我按如下方式初始化 COM 对象时,当我在 VBA 中单步执行调试器时,会出现类型不匹配的情况。
If (IsEmpty(cm)) Then
Set cm = CreateObject("aimd.CMAdaptor")
End If
我可以在 VBA 中添加一个断点并向 cm 变量添加一个监视,然后查看类型与我实例化的类型不匹配。该类型适用于我尝试创建的对象内的属性。指向的对象显然是由我实例化的“aimd.CMAdaptor”对象创建的,我只是没有得到我指定的根对象,只有子对象。
由于这是一个 COM 对象,我想知道我的更新是否可能使用不匹配的 regasm 数据或导致它在错误位置查找对象的内容。我不断地重建它以进行调试,并将其添加到一个安装程序中,该安装程序调用 regasm 作为构建操作。
I have an Excel VBA module calling a C# COM dll.
Sometimes, I get a type mismatch when I step through the debugger in VBA, when I initialize a COM object as follows.
If (IsEmpty(cm)) Then
Set cm = CreateObject("aimd.CMAdaptor")
End If
I can add a breakpoint in the VBA and add a watch to the cm variable, and see the type doesn't match what I instantiated. The type is for a property inside the object I'm trying to create. The object pointed to was clearly created by my "aimd.CMAdaptor" object I instantiated, I just don't get the root object I specify, only the child.
Since this is a COM object, I'm wondering if my updates could be using mismatched regasm data or something that causes it to look for the object in the wrong place. I am constantly rebuilding it for debugging, and adding it to an installer that calls regasm as a build action.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明这是一个愚蠢的错误...我正在复制允许您选择 VBA 端看到的类名称的属性...
[ProgId("aimd.CMAdaptor")]
这位于两个不同的位置类。显然,当你这样做时,没有任何抱怨。我不确定为什么它选择了其中之一,但在更新了不正确的属性后,一切正常。
turned out to be a dumb mistake... I was copying the attributes that allow you to select the name of a class as seen on the VBA side...
[ProgId("aimd.CMAdaptor")]
this was located in two different classes. Apparently, is no complaint when you do this. I'm not sure why it picked one over the other, but after updating the incorrect attribute, everything works fine.