A
A
Alexander2016-01-08 11:44:08
Qt
Alexander, 2016-01-08 11:44:08

C++, Qt, how to use driver functions (dll) correctly?

Welcome all. I apologize in advance, but the question is in the style of "please show me how to make shobeverything was cool."
There is a driver for working with the device via COM-port (transmission goes through FTDI) (the driver is operational and the tests are plowed) with the name "MifareDrv.dll" and the object name AddIn.MifareDrv . By the way, there is even an example of connecting a Delphi driver via OleControl:

uses MifareLib_TLB;
var
 Driver: TMifareDrv;
begin
 Driver := TMifareDrv.Create(nil);
 Driver.Beep;
end;

(there is even on 1C, but I think it is not needed here)
When implementing on Qt, I went through QLibrary. the load method confirms that the driver is being loaded.
Then I decided to test one of the functions as follows.
typedef void (*Connect) (); 
Connect con = (Connect)mylib.resolve ("Beep");
con ();

and such a thing does not want to be executed (it compiles, but it crashes on execution); And so with any functions.
Actually the question is: how to properly implement work with driver functions? Where am I wrong? What other methods can be applied?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2016-01-11
@Psy_Duck

In the end, I decided everything
. In my case, here is the correct code in Visual C ++

// ConsoleApplication5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include "Objbase.h"
#import "MifareDrv.tlb" rename_namespace("mifare") 
CLSID clsid;
mifare::IMifareDrv ;
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); // инициализация COM для ридеров
    hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&pWApp);
    hr = pWApp->QueryInterface(__uuidof(mifare::IMifareDrv), (void **)&pMiDrv);
    pMiDrv->PortNumber = 4;
    pMiDrv->Connect();
    pMiDrv->BeepTone = 1;
    pMiDrv->PcdBeep();
  }
    return 0;
}

And here is the code in Qt
#include <QApplication>
#include <QAxWidget>
QAxWidget *drvFR;
#define CLSID_DrvFR "{450E3DC0-5370-4007-BD5F-90827EC2C2D6}" // это GUID для объекта драйвера (у меня он звался Addin.MifareDrv). GUID вытащил из регистра 
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()");
....
и дописать в .pro write QT += axcontainer.

A
Alexander Ananiev, 2016-01-08
@SaNNy32

Hiking with the driver, you need to work like with a COM object doc.qt.io/qt-4.8/activeqt-container.html

V
Vladimir Martyanov, 2016-01-08
@vilgeforce

Since it's a DLL, it probably has exports. Accordingly, LoadLibrary + GetProcAddress will surely be able to do the same thing that you are trying to do through the code you provided. And in case of errors, GetLastError will show what is wrong. But in general, without the DLL itself, guessing on the coffee grounds.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question