QAxWidget get pointer to my activeX control



  • Hi guys simple question ..maybe :)

    How can I achieve this in Qt:

    // in MFC VC++ project
    CWnd *pdfControl = GetDlgItem( IDC_PDFCREACTIVEX1 );
     ASSERT( pdfControl );
     LPUNKNOWN lpUnknown = pdfControl->GetControlUnknown();
     ASSERT( lpUnknown );
    

    I find this

    ui.myAxWidget.control()
    

    but its return only QString I need LPUNKOWN

    It's really important for me to get pointer to my ActiveX control somehow.

    Thanks in advance



  • Hi, #include "windows.h" and #include "QUuid" and try

    LPUNKNOWN lpUnknown;
    ui.myAxWidget.queryInterface(QUuid(IID_IUnknown),(LPVOID*) &lpUnknown);
    

    Then, to check to really got the correct LPUNKNOWN for your ActiveX control, you can try something like this: (it parties on the LPUNKNOWN above to retrieve some documentation for that ActiveX control)

    LPDISPATCH pDispatch;
    lpUnknown->QueryInterface(IID_IDispatch, (LPVOID*) &pDispatch);
    
    LPTYPEINFO pTypeInfo;
    pDispatch->GetTypeInfo(0,LOCALE_SYSTEM_DEFAULT,&pTypeInfo);
    
    LPTYPELIB pTypeLib;
    UINT uTypeInfoIndex;
    pTypeInfo->GetContainingTypeLib(&pTypeLib,&uTypeInfoIndex);
    
    BSTR bstrName,bstrDocString;
    pTypeLib->GetDocumentation(-1,&bstrName,&bstrDocString,NULL,NULL);
    QString sName((QChar*)bstrName,::SysStringLen(bstrName));
    QString sDocString((QChar*)bstrDocString,::SysStringLen(bstrDocString));
    
    // show what we've got
    qDebug() << sName << sDocString;
    


  • Thanks @hskoglund for reply.
    When I type it like this:

    	LPUNKNOWN lpUnknown;
    	long lo = ui.axWidget->queryInterface(QUuid(ui.axWidget->control()), (LPVOID*)&lpUnknown);
    

    lpUknown is null.

    Thanks in advance!



  • Well that's because ->queryInterface() expects an Interface-flavored UUID, for example IID_IUnknown or IID_IDispatch etc. These are stored in the registry in the HKEY_CLASSES_ROOT\Interface part. You can use either IID_IUnknown as in my example above, or use its string representation like this:
    long lo = ui.axWidget->queryInterface(QUuid("{00000000-0000-0000-c000-000000000046}"), (LPVOID*)&lpUnknown);

    But using a CLSID-flavored UUID, like in your ...ui.axWidget->control())... example above, will fail and return the HRESULT 0x80004002 (No such interface supported)

    Yeah, so there are many types of different UUIDs used in COM, you can read more here


Log in to reply