用一個函數或過程調用DLL ( 积分: 100 )

  • 主题发起人 主题发起人 fusm_2000
  • 开始时间 开始时间
F

fusm_2000

Unregistered / Unconfirmed
GUEST, unregistred user!
因為要調用很多DLL﹐所以想寫一個函數調用它﹐但會出錯﹐請高手指點﹕

procedure TFrmMainManager.Check_receive1Click(Sender: TObject);
var
receivehan:Thandle;
begin
try
receivehan:=loadlibrary('receivedll.dll');
if receivehan<1 then
begin
showmessage('加載動態庫receivedll失敗!');
abort;
end;
receiverev:=getprocaddress(receivehan,'receiverev');
if @receiverev=nil then
begin
showmessage('加載函數receiverev失敗!');
abort;
end;
revout:=receiverev();
finally
freelibrary(receivehan);
end;
 
因為要調用很多DLL﹐所以想寫一個函數調用它﹐但會出錯﹐請高手指點﹕

procedure TFrmMainManager.Check_receive1Click(Sender: TObject);
var
receivehan:Thandle;
begin
try
receivehan:=loadlibrary('receivedll.dll');
if receivehan<1 then
begin
showmessage('加載動態庫receivedll失敗!');
abort;
end;
receiverev:=getprocaddress(receivehan,'receiverev');
if @receiverev=nil then
begin
showmessage('加載函數receiverev失敗!');
abort;
end;
revout:=receiverev();
finally
freelibrary(receivehan);
end;
 
什么错误,把函数的原型和调用约定都写出来,这样,方便大家帮你看一下
 
receiverev:=getprocaddress(receivehan,'receiverev');
这句错了,下面才对.
@receiverev:=getprocaddress(receivehan,'receiverev');
 
那樣寫是沒有問題﹐現在是要調用很多DLL﹐我想每調用它都去調用一個函數﹐這樣就可以節省很多重復的代碼了,我原本想寫成這樣﹐但出錯呀﹕
procedure showform(handlename:Thandle;dllname,data1,data2:string;dlladdr1,dlladdr2:pchar);
begin
handlename:=loadlibrary(pchar(dllname));
if handlename<1 then
begin
showmessage('加載動態庫'+dllname+'失敗!');
abort;
end;
dlladdr1:=getprocaddress(handlename,pchar(data1));
if @dlladdr1=nil then
begin
showmessage('加載函數'+data1+'失敗!');
abort;
end;
dlladdr2:=getprocaddress(handlename,pchar(data2));
if @dlladdr2=nil then
begin
showmessage('加載函數'+data2+'失敗!');
abort;
end;
end;
 
receiverev 声明?
 
聲明過了﹐現在就是要調用很多帶窗體的DLL﹐我不想每次調用它都要寫什么
LOADLIBRARY(DLLANME)什么的﹐請教怎么辦
 
這個問題還沒解決呢﹗請知道的教一下﹗
 
后退
顶部