如何调用某一目录下的DLL(30分)

  • 主题发起人 主题发起人 delphi999
  • 开始时间 开始时间
D

delphi999

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠:<br>&nbsp; &nbsp; 如果我的程序放在c:/run下,而DLL放在C:/run/dll下。<br>&nbsp; &nbsp; 如何调用,能否提供简单的程序段。<br>&nbsp; &nbsp; 万分感谢!
 
LoadLibrary()
 
var<br>&nbsp; h : THandle;<br>&nbsp; fn : function(PARAMETER_LIST_HERE) : RETURN_TYPE;<br>begin<br>&nbsp; h := LoadLibraryEx(DLL_FILE_PATH,0,0);<br>&nbsp; if h=0 then<br>&nbsp; begin<br>&nbsp; &nbsp; showMessage('load library error!');<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; @fn := GetProcAddress(h,PROC_NAME); //case sensitive<br>&nbsp; if @fn=nil then<br>&nbsp; begin<br>&nbsp; &nbsp; showMessage('get proc address error!');<br>&nbsp; &nbsp; FreeLibrary(h);<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; fn(PARAMETER_LIST_HERE); // call proc or function<br>&nbsp; ...<br>&nbsp; FreeLibrary(h);<br>end;<br><br><br>
 
两种方法:<br>&nbsp; &nbsp; 静态调用:function testfunc;far;external 'c:/run/dll/testdll.dll';<br>&nbsp; &nbsp; 动态调用:temphd:=loadlibrary('c:/run/dll/testdll.dll');<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getprocess(...);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; freelibrary(...);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
 
1、LoadLibrary('C:/run/dll/tttt.dll');<br>2、procedure DoSomething; external C:/run/dll/tttt.dll';
 
多人接受答案了。
 
后退
顶部