user911747
user911747

Reputation: 69

Cocreateinstance error

I have developed a COM dll in c++. Now I have a MFC client which uses some of the interfaces exposed by the COM dll. When calling CoCreateInstance from this application, it fails with the following error:80020008 DISP_E_BADVARTYPE. I have added a new interface and a new method in my idl file. I wish to pass structure for which I have defined the structure(with UUID) in the idl file. Now I am passing it as a SAFEARRAY in my method.Please help me understand this error and when does it occur.

Upvotes: 0

Views: 1175

Answers (1)

Ciaran Keating
Ciaran Keating

Reputation: 2783

DISP_E_BADVARTYPE is a COM interop marshalling error. (Is your client compiled with CLR support?) It means that a type can't be marshalled because it's not supported - it's not CLR-compliant, and perhaps not Automation-compatible either.

One cause of this problem is mismatched integer types, such as passing a CLR long integer to a COM dual interface (64-bit integers are not Automation-compatible.)

Another possible cause might be your structure type. SafeArrays of user-defined types are Automation-compatible (VT_ARRAY|VT_RECORD) and so I expect it's possible to do what you want to do. But maybe there's something incompatible in your UDT. Or maybe you've specified it incorrectly, like maybe VT_SAFEARRAY or VT_USERDEFINED.

Can you post your IDL?

Upvotes: 1

Related Questions