简体   繁体   English

初始化COM对象时类型不匹配

[英]Type mismatch when initializing a COM object

I have an Excel VBA module calling a C# COM dll. 我有一个调用C#COM dll的Excel VBA模块。

Sometimes, I get a type mismatch when I step through the debugger in VBA, when I initialize a COM object as follows. 有时,当我按照以下步骤初始化COM对象时,在VBA中逐步调试程序时,会遇到类型不匹配的情况。

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. 我可以在VBA中添加一个断点,并将监视添加到cm变量中,然后查看类型与我实例化的类型不匹配。 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. 指向的对象显然是由我实例化的“ aimd.CMAdaptor”对象创建的,只是没有得到我指定的根对象,只有子对象。

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. 由于这是一个COM对象,所以我想知道我的更新是否使用不匹配的重排数据或某种导致其在错误位置查找对象的东西。 I am constantly rebuilding it for debugging, and adding it to an installer that calls regasm as a build action. 我一直在不断重建它以进行调试,并将其添加到一个调用regasm的安装程序中,以作为构建操作。

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... 原来是一个愚蠢的错误...我正在复制允许您选择在VBA端看到的类名称的属性...

[ProgId("aimd.CMAdaptor")] [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. 我不知道为什么要选择另一个,但是在更新了不正确的属性后,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM