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 writeLIBS += -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.
-
@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? -
@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.