简体   繁体   中英

Type mismatch when initializing a COM object

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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