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 !"));
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]
-
[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()@