Results 1 to 9 of 9

Thread: Access a COM object directly through its IDispatch implementation.

  1. #1
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Access a COM object directly through its IDispatch implementation.

    Hi

    I'm trying to make a Qt GUI Application communicationg with a program called Disto Online. The program provides an API. In the documentation it says: (www.elcovision.com/e_down_disto_online.html)

    "The automatisation interface is made via the IDispatch interface. There a 2 object classes: The class Disto2 which is the application class and the class DistoMeasureProxy (Measure) which represents a measurement. There is also a type library Disto2.tlb. The type library is in the same folder where you installed DISTO online."

    I have been able to communicate by using QAxBase::dynamicCall in the following way.

    Qt Code:
    1. QAxObject *disto = new QAxObject("Disto2.Application");
    2. cout << disto->dynamicCall("DistoVersion");
    To copy to clipboard, switch view to plain text mode 

    The problem, however is that i need to access functions that returns datatypes unsupported by QVariant. So I have to use queryInterface() (as stated in the reference http://doc.qt.nokia.com/4.0/qaxbase.html).

    My question is then ... how? I've been trying to figure this out for ages, but have not succeded in finding the answer.

    This is what I'm thinking: It shoul be possible to use the type library file and from that create a object which I can somehow use. It souds like a simple task but I dont know how to include the tlb-file and how to create such a object?

    Any feedback will be highly appreciated.

  2. #2
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Angry Re: Access a COM object directly through its IDispatch implementation.

    Hi again

    There has been some progress, but I'm still very confused. I have created a header file from my type library file by adding the following to my .pro file.

    Qt Code:
    1. TYPELIBS = $$system( dumpcpp Disto2.tlb -nometaobject )
    To copy to clipboard, switch view to plain text mode 

    And include the generated header file where I want to use it, and it compiles. I'm using the -nometaobject because without it resulted in errors. Is this a problem? Am I just hiding errors that will occure anyway?

    In my new header file there is a namespace Disto2 with two classes Disto2 and DistoMeasureProxy. Disto2 has functions that communicates with the other program and DistoMeasureProxy is the class of the object i want in return from my Disto2 function calls (I think).

    I have no idea what I'm doing but hvae tried things like:

    Qt Code:
    1. QAxObject *distoObject = new QAxObject("Disto2.Application");
    2. QUuid IID_Disto2;
    3. Disto2::Disto2 disto;
    4. distoObject->queryInterface( IID_Disto2, (void**)&disto );
    5. Disto2::DistoMeasureProxy result = disto.SingleMeasure()
    To copy to clipboard, switch view to plain text mode 

    That results in a Error "conversion from 'IDispatch*' to non-scalar type 'Disto2:istoMeasureProxy' requested" (maybe not surpricing ... the smiley is not supposed to be there). Also, for some reason I open two instances of my other program as well.

    I have no idea what to do and if anyone has any feedback I waill be very happy.

    Thanks

  3. #3
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Access a COM object directly through its IDispatch implementation.

    Hmm, this was much harder than I had anticipated ...

    I have gotten the code in this thread to compile: http://www.qtcentre.org/threads/231. It says that the code is "complete". But I have no idea of how to use it. How do I communicate with the API? Do I still need the type library? How?

    For reference the python sample code can be written in 3 lines:
    Qt Code:
    1. import win32com.client
    2.  
    3. disto = win32com.client.Dispatch("disto2.application")
    4. disto.SingleMeasure()
    To copy to clipboard, switch view to plain text mode 
    One would think the Qt/C++ wouludn't be that hard in comparison. There is also some MFC/C++ sample code using COleDispatchDriver class.

    I would like to do all in Qt/C++, but if someone has a solution using either python or MFC in some way I'm interested in hearing that as well.

    Thanks

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access a COM object directly through its IDispatch implementation.

    You should just be able to instantiate an object of type Disto2::Disto2 (as defined in the generated header) and use the proxy methods it provides as if they were native. Let ActiveQt worry about the COM stuff. Something like:
    Qt Code:
    1. Disto2::Disto2 disto;
    2. qDebug() << disto.DistoVersion();
    3. Disto2::DistoMeasureProxy result = disto.SingleMeasure();
    4. ...
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    eirik (22nd July 2010)

  6. #5
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Access a COM object directly through its IDispatch implementation.

    Thanks for yor answer Chris. That is exactly how I want it to work! But I'm not quite sure how to get there.

    Did you answer my second or third post? What you wrote is pretty much like i wrote in my second post in which the call to SingleMeasure() resulted in the conversion error. If it was an answer to my third post, I dont know how to use it. What is iface, what does release() and Invoke really do? (I have tried to read the documentation but it goes way over my head)

    Do you (or somone else) have some more code, or hints.

  7. #6
    Join Date
    May 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Access a COM object directly through its IDispatch implementation.

    did you try using "dumpcpp" tool to generate API files ?

  8. #7
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access a COM object directly through its IDispatch implementation.

    Yes. Just as I said in my second post.
    Qt Code:
    1. TYPELIBS = $$system( dumpcpp Disto2.tlb -nometaobject )
    To copy to clipboard, switch view to plain text mode 
    Had to use the -nometaobject because I got a error if I didn't. Then I include the header files produced. That is working ok I think.

    The problem as I see it (might be totally wrong) is that my functions that I need to call returns a IDispatch* which I have no idea how to use. I want it to magically convert to a class defined in my type library called DistoMeasureProxy.

  9. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Access a COM object directly through its IDispatch implementation.

    I was answering the general request, not so much a specific post. Everything I know about ActiveQt as a COM client comes from the docs in Assistant, specifically http://doc.trolltech.com/4.6/activeqt-container.html and also the Qutlook example.

    Have you tried a minimal example? Something like:

    trial.pro
    Qt Code:
    1. TEMPLATE = app
    2. TARGET = trial
    3. CONFIG += qaxcontainer
    4. TYPELIBS = Disto2.tlb
    5. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 
    main.cpp:
    Qt Code:
    1. #include "disto.h" // <<<<< adjust this to suit the file name generated by dumpcpp
    2. #include <QApplication>
    3. #include <QDebug>
    4.  
    5. int main(int argc, char ** argv)
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. Disto2::Disto disto;
    10. qDebug() << disto.DistoVersion(); // I am assuming this returns QString or an int
    11.  
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Jul 2010
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access a COM object directly through its IDispatch implementation.

    Wow! That worked. I didn't know that I didn't heve to explicitly do the connection myself. That was really helpful.

    I did however have to change the the typelibs parameter from "Disto2.tlb" to "$$system(dumpcpp Disto2.tlb -nometaobject)", because your code didn't produce any header file (wierd?). If I drop the -nometaobject it causes a "reference to Disto2 is ambiguous" error (also wierd?).

    But still the big problem is that I want to call a function that returns an IDispatch*. I might have said in an earlier post that it returns a Disto2:;DistoMeasureProxy, that was just a guess from my side (although it says so in the documentation as well). So my question is still how do I use a *IDispatch, which "in my opinion" should have been a Disto2:;DistoMeasureProxy class object?

    Thanks.

Similar Threads

  1. Replies: 5
    Last Post: 15th June 2010, 07:42
  2. Replies: 4
    Last Post: 9th February 2010, 17:08
  3. How to access an object inside a privateslot
    By graciano in forum Qt Programming
    Replies: 7
    Last Post: 21st January 2009, 18:09
  4. Access an object stored in the list.
    By cbarmpar in forum General Programming
    Replies: 2
    Last Post: 21st September 2008, 20:19
  5. Access an object from another file.
    By cbarmpar in forum General Programming
    Replies: 1
    Last Post: 6th September 2008, 22:17

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.