PDA

View Full Version : problem using VS 2005 created libs within Qt



SteveH
9th July 2010, 21:36
Hi all,

I've a problem using a lib built with VS 2005 within a simple Qt mainwindow program.

My simple test program compiles ok but crashes with a memory exception as soon as I try to access a function out of the VS lib. I've tried commenting out various bits in the project, header and ccp files to make sure the compiler is really using the VS header & lib files which all seems to indicate they are.

I've looked through recent forum posts but most seem to cover Qt in VS not VS libs in Qt, others are more about getting the program to compile (mine does ok). I did come accross a post that helpd get my LIBS and INCLUDEPATH working correctly and another that queried VS in static build (but I haven't found out if my lib is a static build yet).

I assume that VS libs in Qt must be a done deal and it is something simple I am doing wrong. Unfortunately the creators of the lib (Secugen) are not likely give any (free) help and I am going to continue digging through the forum posts in the hope of learning more and resolving it myself, but in the meantime I would be most grateful if anyone can point me to any reference material covering this topic.

For the record I am trying to develop a customer logging program using a fingerprint scanner from Secugen (hamster IV).

SteveH

SteveH
9th July 2010, 22:01
Hi,

Forgot to mention I'm using MinGW on Windows XP

SteveH

squidge
9th July 2010, 22:51
It's typically not that easy (and sometimes impossible) to use MSVC++ libraries under MinGW. Same goes for using MinGW (GCC) libraries under MSVC++.

Therefore, your libraries should be all from the same compiler, otherwise the result will be either linker errors, or crashes at runtime.

If you wish to persist however, then you need to find a GCC calling convention that matches the convention expected by the library, and then modify the header file to suit.

ChrisW67
10th July 2010, 05:16
Have you single stepped to the point of failure and looked at what you are actually passing the function? NULL pointer, wrong data structure etc.

It should be able to work if the Secugen driver interface is pure C (i.e. enclosed in extern "C" {}) and the calling conventions are the same. If you have managed to build and link it then it seems likely the interface is C; C++ names are mangled differently between compiler vendors and won't be found at link time. Can you post the prototype of the failing function call?

Does Secugen's software have an ActiveX interface to the driver? This would be another approach using ActiveQt.

SteveH
10th July 2010, 11:22
Thanks to fatjuicymole and ChrisW67 for your fast replies.

Looking at the header file I can see a Define that looks like it may be for a C++ wrapper elswhere (I will need to add a bit to my prog to find what the setting is).
I will post the header file later this afternoon when I get back to my computer.
The driver progs do come with an ActiveX interface but I have never programmed with those and would like to avoid them for the moment (but now you have pointed it out I will look into them later).

SteveH
10th July 2010, 22:18
Hi again,

I've attached the header file for my problem lib. It does seem to indicate there is C code with a Cpp wrapper that VS would understand.

Working sideways I have tried the lib with my Borland Builder setup which after a tweek does actualy work and run (I used BB's supplied coff2omf.exe program to convert my lib file (to an omf type ??). This will allow me to continue developing my program structure (in BB) but I would still like to convert it to Qt as I find Qt so much nicer now than BB !

Any further help would be appreciated but I can see the problem might be unsurmountable and I may need to start feeding money to Secugen for a lib conversion to something Qt (or more acurately MinGW) understands.

squidge
10th July 2010, 23:29
Well, you can use Visual Studio with Qt Creator, and the express editions are free. Might be easier and cheaper than getting Secugen to convert/relink there libraries.

Looking at your header file, it should be possible to get that to work under GCC. I'm not so sure about there virtual functions in a class surrounded by a "extern C", but if you don't need those functions you should be fine (maybe you can remove them from the header to ensure the compiler doesn't get confused). Just remember to make sure WIN32 is defined before including that header.

SteveH
11th July 2010, 21:36
Thanks fatjuicymile,

Checking through the code I can see that WIN32 and __cplusplus are defined elsewhere and SGFPLIB_EXPORTS is undefined. Given your view that it should be possible to make it work then I am encouraged to press on and spend some time finding the solution. I did come across a post about using QLibrary to get the access to the dll's which I need to checkout further.

Regarding using VS, I will avoid that for the moment since I've very little experiance of it but if all else fails I can use Borland Builder (which I've used for many years) to get the job done. I'll post my findings here later if it helps other users.

squidge
11th July 2010, 22:51
Yes, that is correct. SGFPLIB_EXPORTS should be undefined (you are importing, after all).

If you can link against it, you should be able to call it without problem, there should be no need for QLibrary.

SteveH
6th August 2010, 22:13
hi,

After some further tinkering I have found a workaround for my problem.

1) Firstly to describe what I have been doing before it all went wrong (in case I've missed a trivial Qt step [as usual !])

I've placed sgfplib.h, sgfplib.lib and sgfplib.dll file in my working directory(s).

In the .pro file
HEADERS += mainwindow.h \
sgfplib.h
LIBS += -L"C:\...path to lib...." -lsgfplib

In the MainWindow.h file

#include "sgfplib.h"

Then just put code to use the functions of the lib in MainWindow.cpp (but no Qt specific code to open/attach the lib)

The prog compiles ok but then crashes with an exception error as soon as the prog tries to use code from the lib.

2) Looking at the machine code in debug mode and comparing it with machine code for the same prog in Borland builder I can see that the functionality is pretty much the same regarding the function calls. Using a memory editor I can see that the Qt version seems to just have random code where the lib should be. From this I assume that the dll has not got loaded - Should there be some Qt specific code in the MainWindow::MainWindow routine or elsewhere to explicitly load the dll ?

Just to make sure I'm using Qt with external libraries ok I wrote a simple test lib and another test program to access it (in diferent directories) - everything worked ok for that.

3) My workaround simply uses QLibrary

In the .pro file - delete the LIBS reference

In the MainWindow.h file
#include <QLibrary>

typedef void *HSGFPM ;

typedef DWORD (*f_SGFPM_Create)(HSGFPM *phFPM) ;
... ditto for other lib functions

f_SGFPM_Create SGFPM_Create ;
... ditto for other lib functions

In MainWindow::MainWindow

QLibrary sgfplib("sgfplib") ;

SGFPM_Create = (f_SGFPM_Create) sgfplib.resolve("SGFPM_Create");
... ditto for other lib functions

This compiles and runs ok. It does leave strange (but repeatable) exit codes after quitting which I am tracking down (and are most likely due to the way I am testing the functions of the lib, not Qt)


If anyone has any comments on how I am approaching this or where I went wrong in the first place please feel free - a mouthfull of humble pie sure beats hours of cursing my computer.

SteveH