Results 1 to 6 of 6

Thread: Can't work with COM object

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Can't work with COM object

    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"
    Qt Code:
    1. /*
    2. Class1, IClass1, Class2, IClass2 from files generated with dumpcpp
    3. */
    4. Class1* obj1 = new Class1();
    5. int count = obj1->Count(); // working fine
    6.  
    7. IClass1* iObj1 = NULL;
    8. obj1->queryInterface(IID_IUnknown, reinterpret_cast<void**>(&iObj1));//working fine
    9.  
    10. Class2* obj2 = new Class2();
    11. obj2->Init(iObj1); //QAxBase: Error calling IDispatch member Init: Non-optional parameter missing
    To copy to clipboard, switch view to plain text mode 
    I tried to do the same using VS2010 and WinApi only (without Qt), and it works.
    How to make it work with Qt?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't work with COM object

    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.

  3. #3
    Join Date
    Nov 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't work with COM object

    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?

  4. #4
    Join Date
    Nov 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't work with COM object

    Small addition. There is the code how I invoke this method in VS 2010:
    Qt Code:
    1. IClass1* iboj1
    2. IClass2* iboj2
    3.  
    4. CoCreateInstance(__uuidof(Class1), NULL, CLSCTX_ALL, __uuidof(IClass1), reinterpret_cast<void**>(&iboj1));
    5. CoCreateInstance(__uuidof(Class2), NULL, CLSCTX_ALL, __uuidof(IClass2), reinterpret_cast<void**>(&iobj2));
    6.  
    7. iobj2->Init(iobj2);
    To copy to clipboard, switch view to plain text mode 

    but When I trying the same in Qt I have an error
    Qt Code:
    1. /*
    2. Class1, IClass1, Class2, IClass2 from files generated with dumpcpp
    3. */
    4. Class1* obj1 = new Class1();
    5. int count = obj1->Count(); // working fine
    6.  
    7. IClass1* iObj1 = NULL;
    8. obj1->queryInterface(IID_IUnknown, reinterpret_cast<void**>(&iObj1));//working fine
    9. Class2* obj2 = new Class2();
    10. IClass2* iObj2 = NULL
    11. obj2->queryInterface(IID_IUnknown, reinterpret_cast<void**>(&iObj2));//working fine
    12. iobj2->Init(iObj1); //:-1: error: Exception at 0x759b7199, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance)
    To copy to clipboard, switch view to plain text mode 

    I can't figure out why it happens?

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can't work with COM object

    //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.

  6. #6
    Join Date
    Nov 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Can't work with COM object

    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?

Similar Threads

  1. TypeError: Object [object Object] has no method 'sendData'
    By TheIndependentAquarius in forum Qt Quick
    Replies: 2
    Last Post: 30th November 2013, 05:54
  2. Replies: 1
    Last Post: 8th November 2011, 22:27
  3. Replies: 4
    Last Post: 15th July 2011, 18:31
  4. QScrollArea no work properly in QWizardPage object
    By AleG in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2011, 09:23
  5. Replies: 0
    Last Post: 15th November 2009, 09:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.