Please nominate your Qt Champions for 2021!

Why the program crash after it call the function of DLL compiled by VC++

  • my main program is compiled by QT, and DLL is compiled by VC2005.

    I has add a pushbutton on my dialog, then connect with the SLOT

    connect(ui->btnOK,SIGNAL(clicked()),this, SLOT(onPressButton()));

    and the detail of slot is

    void MainWindow::onPressButton()
    QLibrary lib("AvScanerDrv.dll");
    if(!lib.load() || !lib.isLoaded())
    QMessageBox::warning(this, tr("Warn"),tr("Can't load AvScanerDrv.dll !"));

    typedef int (*funGetCount)(void);
    funGetCount GetScanerCount;
    GetScanerCount = (funGetCount)lib.resolve("J_GetCount");
    QMessageBox::warning(this,tr("Test"),tr("Test this demo"));


    My DLL is simple, the J_GetScanerCount function is :

    extern "C" int PASCAL EXPORT J_GetCount(HWND hParent)
    //HWND hParent ;
    int nCount=0;
    return nCount;

    but the main program would crash after it has displayed the messagebox about ("66","DLL")

    [EDIT: code formatting, please wrap in @-tags, Volker]

  • [quote author="bluevoice" date="1306985636"]my main program is compiled by QT, and DLL is compiled by VC2005.[/quote]No, your main program is not compiled by Qt. Qt is a library, not a compiler.

    I don't know what your program is crashing on though.

  • From what I see, your funGetCount is declared @typedef int (*funGetCount)(void)@, and exported function from dll is declared @int PASCAL EXPORT J_GetCount(HWND hParent)@ Try to export function from dll as: @int PASCAL EXPORT J_GetCount()@

Log in to reply