有点晕了:<br>这个是连接了一个本地MDB库的例子。<br>DLL中的代码:<br>library ConTest;<br>uses<br> ShareMem, //用了string类型做参数,这个引用必须在第一行<br> SysUtils,<br> Classes,<br> windows,<br> ADODB,ACTIVEX;<br>Const<br> ConnStr_Share='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;'<br> +'Mode=Share Deny None;'<br> +'Persist Security Info=False;'<br> +'Jet OLEDB
atabase Password=%s;';<br>var<br> OldExitProc: pointer;<br>{$R *.res}<br>procedure LibExit(Reason: Integer);<br>begin<br> CoUninitialize;<br> ExitProc := OldExitProc;<br>end;<br> function GetExePath:string;<br> {该函数用于取得当前应用程序所在的路径}<br> begin<br> Result:=ExtractFilePath(ParamStr(0));<br> if Result[Length(Result)]<>'/' then<br> Result:=Result+'/';<br> end;<br> function GetCityName(ID:string;Var CityName:string):boolean;stdcall;<br> var<br> ADOConnection:TADOConnection;<br> ADOQTemp:TADOQUERY;<br> begin<br><br> ADOConnection:=TADOConnection.Create(NIL);<br> ADOConnection.ConnectionString:=Format(ConnStr_Share,[GetExePAth+'db.mdb','']);<br> ADOQTemp:=TADOQUERY.Create(NIL);<br> ADOQTemp.Connection:=ADOConnection;<br> try<br> try<br><br> ADOConnection.Open;<br> ADOQTemp.SQL.Add('select city from Tcity where city_id=:ID');<br> ADOQTemp.Parameters.ParamByName('ID').Value:=ID;<br> ADOQTemp.Open;<br> CityName:=ADOQTemp.FieldByName('city').AsString;<br> result:=true;<br> except<br> result:=false;<br> end;<br> finally<br> ADOQTemp.Close;<br> ADOConnection.Close;<br> FreeAndNil(ADOQTemp);<br> FreeAndNil(ADOConnection);<br><br> end;<br> end;<br>exports<br> GetCityName;<br>begin<br> CoInitialize(nil);<br> OldExitProc := ExitProc;<br> ExitProc:= @LibExit;<br>end.<br>//=================<br>主程序中的调用代码:<br>unit main;<br><br>interface<br><br>uses<br> ShareMem,Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls,ComObj, ACTIVEX;<br><br>type<br> TForm1 = class(TForm)<br> Label1: TLabel;<br> Edit1: TEdit;<br> Button1: TButton;<br> Memo1: TMemo;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br>var<br> Form1: TForm1;<br><br>implementation<br>{$R *.dfm}<br>function GetCityName(ID:string;VAR CityName:string): boolean; stdcall; external 'ConTest.dll';<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> CityName:string;<br>begin<br> try<br> if GetCityName(edit1.Text,CityName) then<br> memo1.Lines.Add('查找城市名:'+CityName)<br> else<br> memo1.Lines.Add('查找失败');<br> except<br> <br> end;<br>end;<br>end.<br>主程序调用能正常,也能查找结果,就是在主程序退出时提示非法的指定操作?