Program on Qt crushes multiple use functions from a DLL


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
44 views
Create a blank project in Qt Creator. In the form constructor, connect the DLL and trying to reuse a 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() << the tst(8);
qDebug() << the tst(9);
qDebug() << tst(10);
qDebug() << tst(11);
qDebug() << tst(12);
qDebug() << tst(13);
qDebug() << tst(14);
qDebug() << tst(15);
}


DLLка is in the folder with the project and successfully connects, it is only one function (the DLL project is created in Visual Studio):

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


The crash happens both in release and in debug, and the number of usages of the function before the crash programs are different in debug and relese:

C:\\testettstettd\elease\\testettstettd.exe exited with code -1073741819

For example, now, in release smash 7 iteration use functions from a DLL, and in debug (just weird?!) stopped breaking.

Single use functions from the DLL works. What the hell, the third day went on, trying to understand. Tried to connect without using QLibrary and dynamically and statically. The problem is most likely not the DLL, because it never turns on dllcache and DLL from a project in Delphi successfully connects and works. Well, as usual: PAMAGITE!?
by | 44 views

5 Answers

0 like 0 dislike
I can advise to make the function without the __stdcall modifier and try to build Qt in Debug and there to pick up Qt code and see where the error is displayed.
However, this error is more like Access violation or Stack overflow. Suggest to check the code on other machines with windows. If the problem persists — might overload the stack, which, incidentally, is not surprising, because __stdcall means that the arguments are passed via stack.
Alas, I can not comment on the error and the behavior in the Windows environment, but I advise you to perform it without such a modifier, or replacing any other.
by
0 like 0 dislike
as I understand it the dll and the project itself are going to different compilers? Maybe then the __stdcall case?
by
0 like 0 dislike
I would have tried __stdcall declare and typedef?
by
0 like 0 dislike
All thanks for answers, tomorrow at work I'll try to remove the __stdcall.
by
0 like 0 dislike
Thank you, you all were right. Removed __stdcall and it worked like a clock. Only reason is not very clear, because not familiar with the stack. I will read and learn more, also I would appreciate links to where this is clearly explained.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Apr 12, 2019 by AceLightning
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
110,608 questions
257,186 answers
0 comments
27,959 users