A
A
Aidsoid2010-11-29 18:03:19
Qt
Aidsoid, 2010-11-29 18:03:19

Qt program crashes when using DLL function multiple times

I create a clean project in Qt Creator. In the form constructor, I include the DLL and try to reuse the function from the DLL:

MainWindow :: MainWindow ( QWidget  * parent )  :
    QMainWindow ( parent ) ,
    ui ( new  Ui :: MainWindow )
{
    ui - > setupUi ( this ) ;
 
    QLibrary  * library  =  new  QLibrary ( "UniversalDLL.dll" ) ;
 
    typedef  int  ( * testFunc ) ( int ) ;
    testFunc tst  =  ( testFunc )  library - > resolve ( "wrr" ) ;
    if  ( ! tst )
    {
        QMessageBox :: critical ( this , this - > windowTitle ( ) , tr ( "Error loading DLL!" ) ) ;
        exit ( 0 ) ;
    }
 
    qDebug ( )  <<  tst ( 1 ) ;
    qDebug ( )  <<  tst ( 2 ) ;
    qDebug ( )  <<  tst ( 3 ) ;
    qDebug ( )  <<  tst ( 4 ) ;
    qDebug ( )  <<  tst ( 5 ) ;
    qDebug ( )  <<  tst ( 6 ) ;
    qDebug ( )  <<  tst ( 7 ) ;
    qDebug ( )  <<  tst ( 8 ) ;
    qDebug ( )  <<  tst ( 9 ) ;
    qDebug ( )  <<  tst ( 10 ) ;
    qDebug ( )  <<  tst ( 11 ) ;
    qDebug ( )  <<  tst ( 12 ) ;
    qDebug ( )  <<  tst ( 13 ) ;
    qDebug ( )  <<  tst ( 14 ) ;
    qDebug ( )  <<  tst ( 15 ) ;
}


The DLL is located in the folder with the project and is successfully connected, it has one single function (the DLL project was created in Visual Studio):

extern  "C"  __declspec ( dllexport )  int  __stdcall wrr ( int  abonent )
{
return  abonent ;
}


The program crash occurs both in release and debug, and the number of function usages before the program crash is different in debug and release:

C:\testettstettd\release\testettstettd.exe terminated with code -1073741819

For example, now, in release it crashes on 7 iterations using a function from a DLL, but in debug (already strange?!) it no longer crashes.

Single use of a function from a DLL works. What nonsense, the third day went, as I try to figure it out. Tried to connect without using QLibrary both dynamically and statically. The problem is most likely not in the DLL, because. checked on different DLL and DLL from the project on Delphi successfully connects and works. Well, as usual: PAAAMAGIITEE!?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
DeNnEr, 2010-11-29
@Aidsoid

I can advise you to make a function without the __stdcall modifier and try to build Qt in Debug, and then pick up the raw Qt and see where the error occurs.
However, this error looks more like an Access violation or Stack overflow. I advise you to test the code on other machines with windows. If the problem persists, it may be a stack overload, which, by the way, is not surprising, because __stdcall means that arguments are passed through the stack.
Alas, I cannot comment on this error and behavior in the Windows environment in any way, but I advise you to analyze it without such a modifier, or replacing it with some other one.

A
adminimus, 2010-11-29
@adminimus

as I understood dll and the project itself are assembled by different compilers? Maybe it's in __stdcall then?

M
MikhailEdoshin, 2010-11-29
@MikhailEdoshin

I would try __stdcalldeclaring in typedef?

A
Aidsoid, 2010-11-29
@Aidsoid

Thank you all for your answers, tomorrow at work I'll try to remove __stdcall.

A
Aidsoid, 2010-11-30
@Aidsoid

Thanks, you were all right. Removed __stdcall and everything worked like clockwork. Only the reason is not very clear, because. not yet familiar with the stack. I will read and devote myself, I will also be grateful for links where this is explained in an accessible way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question