Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why the program crash after it call the function of DLL compiled by VC++
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bluevoice
    wrote on last edited by
    #1

    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 !"));
    return;
    }

    typedef int (*funGetCount)(void);
    funGetCount GetScanerCount;
    GetScanerCount = (funGetCount)lib.resolve("J_GetCount");
    if(GetScanerCount!=NULL)
    GetScanerCount();
    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)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    //HWND hParent ;
    int nCount=0;
    ::MessageBox(NULL,_T("66"),_T("DLL"),MB_OK);
    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]

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      [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.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cincirin
        wrote on last edited by
        #3

        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()@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved