怎么动态调用在DLL文件里的过程,动态调用,请给出Code!(41分)

  • 主题发起人 主题发起人 lovenuo
  • 开始时间 开始时间
L

lovenuo

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么动态调用在DLL文件里的过程,动态调用,请给出Code!
 
procedure TForm1.Button1Click(Sender: TObject); <br>type <br>TIntFunc=function(i:integer):integer;stdcall; <br>var <br>Th:Thandle; <br>Tf:TIntFunc; <br>Tp:TFarProc; <br>begin <br>Th:=LoadLibrary(’Cpp.dll’); {装载DLL} <br>if Th&gt;0 then <br>try <br>Tp:=GetProcAddress(Th,PChar(’TestC’)); <br>if Tp&lt;&gt;nil <br>then begin <br>Tf:=TIntFunc(Tp); <br>Edit1.Text:=IntToStr(Tf(1)); {调用TestC函数} <br>end <br>else <br>ShowMessage(’TestC函数没有找到’); <br>finally <br>FreeLibrary(Th); {释放DLL} <br>end <br>else <br>ShowMessage(’Cpp.dll没有找到’); <br>end;
 
动态调用过程,不是函数!
 
procedure TForm1.Button1Click(Sender: TObject); <br>type <br>TIntFunc=function(i:integer):integer;stdcall; <br>var <br>Th:Thandle; <br>Tf:TIntFunc; <br>Tp:TFarProc; <br>begin <br>Th:=LoadLibrary(’Cpp.dll’); {装载DLL} <br>if Th&gt;0 then <br>try <br>Tp:=GetProcAddress(Th,PChar(’TestC’)); <br>if Tp&lt;&gt;nil <br>then begin <br>Tf:=TIntFunc(Tp); <br>Tf(1); {调用TestC &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;过程} <br>end <br>else <br>ShowMessage(’TestC函数没有找到’); <br>finally <br>FreeLibrary(Th); {释放DLL} <br>end <br>else <br>ShowMessage(’Cpp.dll没有找到’); <br>end;
 
后退
顶部