C++, Qt, how do you correctly use Driver functions (dll)?
-
There's a COM-port drip to handle the device, with the name "MifareDrv.dll" and the name AddIn.MifareDrv. In fact, there's an example of an OleControl to connect a driver to a business:
uses MifareLib_TLB; var Driver: TMifareDrv; begin Driver := TMifareDrv.Create(nil); Driver.Beep; end;
(even on 1C, but I don't think it's necessary here) When applied to Qt went through QLibrary, the load method confirms that the driver is loaded. Then I decided to check one of the functions as follows.
typedef void (*Connect) (); Connect con = (Connect)mylib.resolve ("Beep"); con ();
and does not want to do such a case (compiled, but it falls); and so does any function. In fact, the question is, how do you properly work with the role of the driver? What am I wrong? What other ways can we use?
UPD: Version under Visual C+++
#include "stdafx.h" #include <windows.h> #include "Objbase.h" #import "MifareDrv.tlb" rename_namespace("mifare") // с dll тоже должно работать 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's the answer to 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.
-
Based on Delphi.
MifareDrv.dll
is the COM library. You're an example.QLibrary
You're trying to use it as a normal "baby" DL, which is not right. To useMifareDrv.dll
Use basic toolsCOM
From Vijual Studio.Well, it's easier to show the code. Here's your example for Delphi translated into C+++, Vijual Studio:
// Если не жмет, можно абсолютный путь указать. // Переименование пространства имен бибилотеки MifareDrv делается // для того, чтобы точно знать кокое у этого простарнства будет имя #import "MifareDrv.dll" rename_namespace("mifare")
CLSID driver_clsid;
if(SUCCEEDED(CLSIDFromProgID(__T("AddIn.MifareDrv"), &driver_clsid))
{
mifare::IMifareDrvPtr driver;
if(SUCCEEDED(driver.CreateInstance(driver_clsid))
{
driver->Beep();
}
}
Directive https://msdn.microsoft.com/en-us/library/8etzzkb6.aspx It specific to C++ from the Visual Studio, it performs the following:
- Loads the library description file */tlb from the location in question, this example imports DL and file *.tlb is contained as a resource
- Based on the file received *.tlb generates C+++ headline file with a name
<имя библиотеки>.tlh
and a name-plate<имя библиотеки>.tli
- In addition, in the file, *.tlh for each interface found in the library generates a smart indicator statement. https://msdn.microsoft.com/en-us/library/417w8b3b.aspx by name
<имя интерфейса>Ptr
♪ Like this.IMifareDrvPtr
♪
I will like to point out that this example may not be computed because of the fact that it is in the library
MifareDrv.dll
No interface.IMifareDrv
♪ In order to know his exact name, first, read the documentation for the library, second, carefully examine the contents of the generated head restraint.MifareDrv.tlh
♪