Exe 调用 ADO检索的 dll 文件,在关闭 exe 文件时,报错了~~~
dll 文件源码如下:
extern "C" __declspec(dllexport) void __stdcall ListON(TListView *ListView)
{
TListItem *NewItem;
TADOQuery *Query = new TADOQuery(Application);
Query->ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExtractFilePath(Application->ExeName) + "MyDat.dat;Jet OLEDB:Database Password=aabbccdd;";
Query->SQL->Text = "select name from table1";
Query->Open();
ListView->Clear();
while(!Query->Eof)
{
ListView->AddItem(IntToStr(ListView->Items->Count+1),0);
NewItem = ListView->Items->Item[ListView->Items->Count-1];
NewItem->SubItems->Add(Query->FieldByName("name")->AsString);
NewItem->ImageIndex = 1;
Query->Next();
}
delete Query;
}
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Exe 文件源码如下:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE Hdl;
Hdl=::LoadLibrary("Test.dll");
void __stdcall (*ListON)(TListView *);
ListON = (void __stdcall (*)(TListView *))::GetProcAddress(Hdl,"ListON");
ListView1->Clear();
ListON(ListView1);
::FreeLibrary(Hdl);
}
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
执行 Button1 的点击事件时,列表正常,就是稍慢一点,但在关闭 Form1 时,会出现下面出错提示:
Access violation at address 004522B2 in module 'ThisExe.exe'. Write of address 010FE1D0.
请各位老大帮助看看原因出在什么地方了?