3

A friend of mine asked me to create an application to control some things with the use of an "Velleman VM167". This VM167 is nothing more than a USB interface card with some GPIO's and a few ADC's.

This VM167 comes with an SDK consisting of two DLL's (VM167.dll and MPUSBAPI.dll where is suspect that the alst one is used within the first DLL) and a header file VM167.h

I've used the card before in successfully Delphi but now wanted to make the conversion to Qt. And as this is just a simple project I thought this might be the right time.

What I've want to do is import the DLL and use the functions implemented in that DLL. I've tried a lot of thing and googled a lot of tutorials but they always use a .lib or a .a file. Which I don't have. Is there a way to use this DLL and control the card using Qt?

Im using Qt 5.3 with the MinGW 32 bit compiler.

Link to the product description and SDK download: http://www.velleman.eu/products/view/?country=be&lang=en&id=384006

Deduplicator
  • 44,692
  • 7
  • 66
  • 118

2 Answers2

4

Since you're using Qt, you can use QLibrary and in particular its resolve method.

MSalters
  • 173,980
  • 10
  • 155
  • 350
2

The way to use a Windows DLL with no LIB file from C/C++ is via LoadLibrary and GetProcAddress.

There's are some examples for this in the VM167 SDK you linked to, one in Examples\VM167DemoBCB_dynamic_load\Unit1.cpp and another in Examples\VM167DemoDevC\main.cpp.

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • Thanks for pointing me out to the right examples! this along with the Qlibrary class info at the QT site got me up and running really quick. The bad thing is, i've no idea what my code does... Could you briefly explain what's going one here? QLibrary VMDLL("VM167"); typedef int (*VOID2INT)(void); VOID2INT OpenDevices = (VOID2INT) VMDLL.resolve("mysymbol"); My idea is that i create a Typedef with the corresponding arguments and result as a type. I then create an instance of this type and then set it's pointer address to the pointer address of the actual function in the DLL. somehting correct? – DisplayName Jun 03 '14 at 14:42
  • @Jetse: Yes, you've understood it perfectly. You need the typedef so that the compiler knows how to pass arguments to the function, and what return type to expect. QLibrary does the job of loading the DLL and finding the function you want, then returns you a pointer to that function, which you then call through that pointer. – RichieHindle Jun 03 '14 at 15:19