TransWikia.com

Why loading a library dynamically makes my app crash?

Stack Overflow Asked by jpo38 on December 7, 2021

I have a very simple Qt 5.12.0/VS2015 program loading a third party library (DX5100_v2.dll from "DX5100 API/DLL for C++" at https://www.tec-microsystems.com/downloads.html), running under Win10.

Here is the code:

#include <QPushButton>
#include <QStyle>
#include <QDialog>
#include <QApplication>

#include <objbase.h>

int main( int argc, char* argv[] )
{
    QApplication app( argc, argv );

    HMODULE handle = LoadLibrary( "DX5100_v2.dll" );

    QDialog dlg;
    dlg.setWindowIcon( qApp->style()->standardIcon( QStyle::SP_MessageBoxInformation ) );
    dlg.show();

    return app.exec();
}

This crashs reporting "0xC0000090: Floating-point invalid operation" with stack:

>   Qt5Guid.dll!reciprocal_mul_ps(__m128 a, float mul) Ligne 101    C++
    Qt5Guid.dll!convertARGBFromARGB32PM_sse4<0,0>(unsigned int * buffer, const unsigned int * src, int count) Ligne 122 C++
    Qt5Guid.dll!storeARGB32FromARGB32PM_sse4(unsigned char * dest, const unsigned int * src, int index, int count, const QVector<unsigned int> * __formal, QDitherInfo * __formal) Ligne 298    C++
    Qt5Guid.dll!convert_generic(QImageData * dest, const QImageData * src, QFlags<enum Qt::ImageConversionFlag> flags) Ligne 217    C++
    Qt5Guid.dll!QImage::convertToFormat_helper(QImage::Format format, QFlags<enum Qt::ImageConversionFlag> flags) Ligne 2091    C++
    Qt5Guid.dll!QImage::convertToFormat(QImage::Format f, QFlags<enum Qt::ImageConversionFlag> flags) Ligne 188 C++
    Qt5Guid.dll!qt_imageToWinHBITMAP(const QImage & imageIn, int hbitmapFormat) Ligne 280   C++
    Qt5Guid.dll!qt_pixmapToWinHBITMAP(const QPixmap & p, int hbitmapFormat) Ligne 360   C++
    Qt5Guid.dll!qt_pixmapToWinHICON(const QPixmap & p) Ligne 469    C++
    qwindowsd.dll!createHIcon(const QIcon & icon, int xSize, int ySize) Ligne 2642  C++
    qwindowsd.dll!QWindowsWindow::setWindowIcon(const QIcon & icon) Ligne 2652  C++
    Qt5Guid.dll!QWindow::setIcon(const QIcon & icon) Ligne 1000 C++
    Qt5Widgetsd.dll!QWidgetPrivate::setWindowIcon_sys() Ligne 6209  C++
    Qt5Widgetsd.dll!QWidget::create(unsigned __int64 window, bool initializeWindow, bool destroyOldWindow) Ligne 1359   C++
    Qt5Widgetsd.dll!QWidget::setVisible(bool visible) Ligne 8274    C++
    Qt5Widgetsd.dll!QDialog::setVisible(bool visible) Ligne 739 C++
    Qt5Widgetsd.dll!QWidget::show() Ligne 7875  C++
    dx5100_load_crash.exe!main(int argc, char * * argv) Ligne 18    C++
    dx5100_load_crash.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Ligne 104  C++

Also note that it does not crash anymore:

  • If I remove setWindowIcon call….but there’s no reason for this function to lead to a crash, looks like I end up in an unstable state and icon display leads to a crash?
  • If I remove LoadLibrary( "DX5100_v2.dll" )
  • More surprisingly, if I generate DX5100_v2.lib file (generated DX5100_v2.def using depends.exe to get functions list, and then invoked lib /def:DX5100_v2.def /machine:x64 /out:DX5100_v2.lib from VS2015 command line prompt), and link to it (so that DX5100_v2.dll is loaded at startup, even before main entry point is executed)…it does not crash.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP