PDA

View Full Version : Can't work with COM object



giker
17th November 2015, 22:02
I have 3d party library. This library written like Com-object using VS2010. It provides a lot of classes and interfaces. I used dumpcpp util for creation .h and .cpp files. I can create classes of the library and invoke their functions. But some functions require interface classes for the arguments. I can create the interface classes using QaxBase::queryInterface method. But when I invoke the functions I have the error "QAxBase: Error calling IDispatch member Init: Non-optional parameter missing"


/*
Class1, IClass1, Class2, IClass2 from files generated with dumpcpp
*/
Class1* obj1 = new Class1();
int count = obj1->Count(); // working fine

IClass1* iObj1 = NULL;
obj1->queryInterface(IID_IUnknown, reinterpret_cast<void**>(&iObj1));//working fine

Class2* obj2 = new Class2();
obj2->Init(iObj1); //QAxBase: Error calling IDispatch member Init: Non-optional parameter missing

I tried to do the same using VS2010 and WinApi only (without Qt), and it works.
How to make it work with Qt?

d_stranz
18th November 2015, 00:24
Error calling IDispatch member Init: Non-optional parameter missing

It seems sort of obvious from this error message exactly what is wrong. Look at the signature for the Init method and figure out what parameter you need to add.

giker
18th November 2015, 03:43
Thank you for your answer. I checked signature of the method several times. I have signature of the method from files that dumpcpp created for me. I think compiler doesn't allow me to invoke the method with another quantity of arguments because declaration of the method contains only one argument. Even more in VS 2010 I invoke this method with one argument. Where can I check signature of the method?

giker
18th November 2015, 13:50
Small addition. There is the code how I invoke this method in VS 2010:


IClass1* iboj1
IClass2* iboj2

CoCreateInstance(__uuidof(Class1), NULL, CLSCTX_ALL, __uuidof(IClass1), reinterpret_cast<void**>(&iboj1));
CoCreateInstance(__uuidof(Class2), NULL, CLSCTX_ALL, __uuidof(IClass2), reinterpret_cast<void**>(&iobj2));

iobj2->Init(iobj2);


but When I trying the same in Qt I have an error


/*
Class1, IClass1, Class2, IClass2 from files generated with dumpcpp
*/
Class1* obj1 = new Class1();
int count = obj1->Count(); // working fine

IClass1* iObj1 = NULL;
obj1->queryInterface(IID_IUnknown, reinterpret_cast<void**>(&iObj1));//working fine
Class2* obj2 = new Class2();
IClass2* iObj2 = NULL
obj2->queryInterface(IID_IUnknown, reinterpret_cast<void**>(&iObj2));//working fine
iobj2->Init(iObj1); //:-1: error: Exception at 0x759b7199, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)


I can't figure out why it happens?

d_stranz
18th November 2015, 16:36
//working fine

No, it isn't. You initialize the iObj2 pointer to NULL, call queryInterface() to set its value, and don't bother to check the return value of the queryInterface() method to see if it actually succeeded. So, iObj2 is still probably NULL, and calling through a NULL pointer will cause exactly the result you see.

giker
18th November 2015, 16:58
I cheked the result of queryInterface() it is equal 0 (it means that interface is initialized properly), and the iObj2 pointer is not equal NULL after queryInterface() call. I see it in "Locals and Expressions" window.
It seems me that qt_metacall function is not working properly. I mean It can't find proper function in COM object.
Or I'm wrong?