COM object + dll



  • Hello all. I need work with cardreader in QT using driver and dll. I just show you code at VS:

    #include "stdafx.h"
    #include <windows.h>
    #include "Objbase.h"
    #import "MifareDrv.dll" rename_namespace("mifare") 
    CLSID clsid;
    IDispatch *pWApp;
    mifare::IMifareDrv *pMiDrv;
    int _tmain(int argc, _TCHAR* argv[])
    {
    	HRESULT hr = CLSIDFromProgID(L"Addin.MifareDrv", &clsid);
    	if (SUCCEEDED(hr))
    	{
    		LPOLESTR tmpbuf;
    		StringFromCLSID(clsid, &tmpbuf);
    		CoInitializeEx(NULL, COINIT_MULTITHREADED);
    		hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&pWApp);
    		hr = pWApp->QueryInterface(__uuidof(mifare::IMifareDrv), (void **)&pMiDrv);
    		pMiDrv->FindDevice();
    		pMiDrv->Connect();
    		pMiDrv->BeepTone = 1;
    		pMiDrv->PcdBeep();
    
    	}
    		return 0;
    }
    

    I rewriting this code for Qt but trying to stick to the original.
    In pro. i write

    LIBS += -lole32 -loleaut32 -luuid
    

    in .cpp:

    #include <QCoreApplication>
    #include "windows.h"
    #include "objbase.h"
    #include <QLibrary>
    CLSID clsid;
    IDispatch *pWApp;
    HRESULT hr = CLSIDFromProgID(L"Addin.MifareDrv", &clsid);
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QLibrary myLib ("MifareDrv.dll");
        myLib::IMifareDrv *pMiDrv;
        LPOLESTR tmpbuf;
        StringFromCLSID(clsid, &tmpbuf);
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&pWApp);
        hr = pWApp->QueryInterface(QUuid(__uuidof(myLib::IMifareDrv)), (void **)&pMiDrv);
    
        return a.exec();
    }
    

    And yep, i have trouble with "myLib::IMifareDrv". Can anybody help me to write and how to replace me "#import"? Or how this code should look with QAxBase.



  • Hi, if you have the .tlb file for the MiFare driver, instead of #importing, you could try using Qt's dumpcpp utility
    For a good example on how to use it, see here



  • @hskoglund I'm trying it. I create cpp and h, but when I wrote the code I got the next problem: "return type 'struct MifareLib::TSAMVersion' is incomplete
    inline TSAMVersion MifareDrv::SAMVersion() const"
    I find TSAMVersion, it struct has prototype, but hasn't realization.
    Do you have any idea?



  • Hi, maybe that SAMVersion() function is not important, you could try commenting it out...



  • @hskoglund i decided to throw off their problem and the code here, can someone else help
    #include <QApplication>
    #include <QAxWidget>
    QAxWidget *drvFR;
    #define CLSID_DrvFR "{450E3DC0-5370-4007-BD5F-90827EC2C2D6}" // it's GUID for driver object (my Addin.MifareDrv). GUID can be found in registry
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    drvFR = new QAxWidget();
    drvFR->setControl(CLSID_DrvFR);
    drvFR->dynamicCall("FindDevice()");
    drvFR->dynamicCall("Connect()");
    drvFR->setProperty("BeepTone", 1);
    drvFR->dynamicCall("PcdBeep()");
    ....
    and of course in .pro write QT += axcontainer.

    Thank you for trying help.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.