问大家一个关于DLL调用小问题?对大家来说应该很简单
我做了有一个三层的很简单的例子,我把它封装成DLL,再用另外的应用程序调用它
连续点击调用前面7、8次还没有问题,我大约再10次的时候就会出现没有响应的情况
想问问大家这到底是怎么回事?谢谢大家
应用服务器程序:
procedure Ttestapp.RemoteDataModuleCreate(Sender: TObject);
begin
ADOConnection1.ConnectionString :=' Provider=SQLOLEDB.1;'+
'Persist Security Info=False;User ID='+GetRegInfo(3)+';Password='+GetRegInfo(4)+';'+
'Initial Catalog='+GetRegInfo(2)+';Data Source='+GetRegInfo(1);
end;
procedure Ttestapp.mm;
begin
ADODataSet1.Close;
ADODataSet1.CommandText:='select * from MaintManView';
ADODataSet1.Open;
end;
initialization
TComponentFactory.Create(ComServer, Ttestapp,
Class_testapp, ciMultiInstance, tmApartment);
end.
客户端程序:
var
Form1: TForm1;
procedure showform;export;
Function GetRegInfo(Flag:Integer):ShortString;external 'OPUHIS.DLL';
implementation
uses Unit2;
{$R *.dfm}
procedure showform;
begin
CoInitialize(Nil);
DataModule2 := TDataModule2.Create(Application);
Form1:=TForm1.Create(Application);
with Form1 do begin
ShowModal;
CoUnInitialize;
DataModule2.Free;
Free;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
DataModule2.SocketConnection1.AppServer.mm;
DataModule2.ClientDataSet1.Open;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
LinkMode:=GetRegInfo(5);
if LinkMode = '0' then begin //Socket方式连接
DataModule2.SocketConnection1.Host := GetRegInfo(0);
Try //检查网络是否通或应用服务器是否运行
DataModule2.SocketConnection1.Connected := True;
except
Application.MessageBox('请检查scktsrvr.exe是否运行或Ping网络?','提示',64);
Application.Terminate;
end;
DataModule2.ClientDataSet1.RemoteServer :=DataModule2.SocketConnection1;
Apps:=DataModule2.SocketConnection1.AppServer
end else begin //DCOm方式连接
DataModule2.DCOMConnection1.ComputerName := GetRegInfo(0);
Try //检查网络是否通或应用服务器是否运行
DataModule2.DCOMConnection1.Connected := True;
except
Application.MessageBox('请检查DCOM是否注册或Ping网络?','提示',64);
Application.Terminate;
end;
DataModule2.ClientDataSet1.RemoteServer := DataModule2.DCOMConnection1;
Apps:=DataModule2.DCOMConnection1.AppServer;
end;
end;
输出过程:exports
showform;
调用DLL程序:
procedure TForm1.Button1Click(Sender: TObject);
var
Sabout:THandle;
ShowA:procedure;
begin
KillDll('Project1.dll');
Sabout := LoadLibrary('Project1.dll');
if Sabout=0 then begin
Application.MessageBox('动态连接库Project1.dll文件不存在!','错误',64);
exit;
end;
ShowA := GetProcAddress(Sabout,'showform');
showA;
FreeLibrary(Sabout);
end;