Hello,
I would like to know how to use the QLibrary to read a DLL library and call its functions.
I'll appreciate if someone could give me an example.
Thanks
Hello,
I would like to know how to use the QLibrary to read a DLL library and call its functions.
I'll appreciate if someone could give me an example.
Thanks
You don't use QLibrary to use a DLL in your application.
Just include the header file of the library, and link the library to your application.
Note that you can not use QLibrary to easily load C++ symbols. So, if your library is written in C++ and it doesn't extern C its symbols, you'll need a bit of work to get the correct symbols.
You cannot use QLibrary to scan a shared library to see what symbols it has. You need to get that list from the library's creator.
Once you know what's inside the library, you need to know the types of the symbols that you wish to access. These could be functions, classes or variables. In the case of functions, you need to know the function signature, in the case of classes, you need the class definition and in the case of variables, you need to have the data type. All these should be supplied by the creators in header files and/or DEF files.
Once you've decided what you need, you can load the library into memory using QLibrary (see Assistant) and then find the symbol's address using QLibrary::resolve(), converting the void* to the data type that the symbol represents.
how about if I use the function LoadLibrary? is that supported by QT?
Added after 11 minutes:
Thanks for the reply Robbie.
I already know what is inside the library. I'm talking about the mpusbapi.dll from microchip, I already have all the headers and sources code but specific to the boorland c++ builder compiler, so from there I can get the list of the function that I want to use.
How can I proceed from here? I need to make a DEF file?
Last edited by digog; 3rd November 2010 at 15:09.
I guess there's something fundamental you do not understand.I already have all the headers
You have the DLL, that's ok.
You have the headers (.h file) that's great.
Now, include the header file in your own source code and link the dll with your program.
Something in the lines of LIBS += -lmpusbapi should be added to your .pro file
I think what he really lacks is the import library but as far as I know this can be regenerated from the dll.
Thats ok.
The .h file is specific to the borland c++ compiler. I don't know if I can just include this .h file in my own project.You have the headers (.h file) that's great.
dont I need to have the .lib file for this? I have one here but, as I said before, its specific to the borland c++ compiler.link the dll with your program.
Something in the lines of LIBS += -lmpusbapi should be added to your .pro file
Sorry if I making a big confusion, its just all new for me.
The .h file holds the function prototypes which you will need with QLibrary too. So this is a problem you will have to resolve either way.
http://jrfonseca.planetaclix.pt/proj...imp/index.htmldont I need to have the .lib file for this? I have one here but, as I said before, its specific to the borland c++ compiler.
I'm sure there is an equivalent for Turbo C++.
What should I do with it?http://jrfonseca.planetaclix.pt/proj...imp/index.html
I'm sure there is an equivalent for Turbo C++.
Isn't there a tutorial?
And do you think that this program, that I found on internet, can resolve my problem?
Here is the link:
http://www.softpedia.com/get/Program...L-to-Lib.shtml
Last edited by digog; 4th November 2010 at 14:58.
The dll is not a Borland DLL, it is compiler independent as you can see in the readme file that comes with the dll:
So I think that I just need a program that could create an import library compatible with MinGW, right?Release Notes for MPUSBAPI Library, Microchip Technology Inc.
v1.00
19 November 2004
----------------------------------------------------------------------
1. What is MPUSBAPI Library?
----------------------------------------------------------------------
* MPUSBAPI is a DLL module providing wrapper functions for the
Microchip General Purpose USB Windows driver, mchpusb.sys.
It abstracts out the complexity in working with Win32 API functions.
* Seven basic functions are provided in this release:
- MPUSBGetDeviceCount
- MPUSBOpen
- MPUSBClose
- MPUSBRead
- MPUSBReadInt
- MPUSBWrite
- MPUSBGetDLLVersion
* Details on how to use each function are documented in the source code
- Refer to \DLL\Borland_C\Source\_mpusbapi.cpp
----------------------------------------------------------------------
2. Linking MPUSBAPI to your project
----------------------------------------------------------------------
There are two ways to link the DLL to your project:
a) Load-time Linking
Simply add the mpusbapi.lib file to your project.
The mpusbapi.lib file provided is specific to the Borland C++
compiler. The mpusbapi.dll is compiler independent. If a different
compiler is used, however, the DLL must be re-compiled to generate
a new mpusbapi.lib specific to that compiler.
C++ source code for MPUSBAPI is provided.
The _mpusbapi.h file must be included in every file that uses
the MPUSBAPI functions.
The mpusbapi.dll file must be in the same directory as the
executable file.
b) Run-time Linking
Run-time Linking does not require the .lib file. It only requires
the .dll file. Linking the functions is, however, a little more
complicated. An example is provided showing how to use Win32
API functions to load a DLL.
The mpusbapi.h file (note, no "_") must be included in every file
that uses the MPUSBAPI functions.
The mpusbapi.dll is not required to be in the same directory as
the executable file.
What about the dlltool? can it resolve my problem?
As easy as that.If a different compiler is used, however, the DLL must be re-compiled to generate a new mpusbapi.lib specific to that compiler.
Bookmarks