动态调用dll时的问题。请高手帮助(100分)

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

fxh7622

Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我调用动态连接库的代码,为什么 GetprocAddress的返回值总是NIL呢???<br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls, Mask, &nbsp;ComCtrls, ToolWin, Menus, RzTreeVw, RzListVw,<br>&nbsp; ExtCtrls, KindFormCaption, KindMenu, ImageStatus, ImgList, IEButton,<br>&nbsp; dcOutBar, dcOutPanel;<br>Type TDllStr=Function :String;<br><br><br>type<br>&nbsp; TFormMain = class(TForm)<br>&nbsp; &nbsp; MainMenu: TMainMenu;<br>&nbsp; &nbsp; ToolBar1: TToolBar;<br>......<br>.....<br>var<br>&nbsp; Main:TMenuItem;<br>&nbsp; Found:Integer;<br>&nbsp; sr:TSearchRec;<br>&nbsp; Handle:THandle;<br>&nbsp; DirFile,DllFile:String;<br>&nbsp; Proc:TFarproc;<br>......<br><br><br>&nbsp; &nbsp;<br>DllFile:=Dir+'/'+sr.Name;<br>&nbsp; &nbsp; Handle:=LoadLibrary(Pchar(DllFile));<br>&nbsp; &nbsp; if Handle&lt;HINSTANCE_ERROR &nbsp;then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Application.MessageBox('加载动态库失败','失败',MB_OK);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Proc:=GetprocAddress(Handle,'Getinfo');<br>&nbsp; &nbsp; &nbsp;......<br><br><br>
 
@Proc:=GetprocAddress(Handle,'Getinfo');<br>if @Proc = nil then<br>&nbsp; RaiseLastOSError;
 
xianjun不正确,根本不能运行的。提示错误在GetprocAddress行。
 
请大家帮助呀!!!!
 
@Proc:=GetprocAddress(Handle,'Getinfo');&lt;&lt;这儿应该是楼主的对吧<br>单步调试的时候走到上面这一句了吗?
 
如果像那样用<br>proc:TDllStr这样声明才对<br>
 
走到了,可是过了GetprocAddress后查看Proc=nil
 
52free 你说的方法我试了,好像也是不正确的。就在GetprocAddress一句
 
能给我一个调用一个DLL后有返回值(string类型)的例子吗?谢谢了。
 
Getinfo在dll中有没有导出
 
52free 在dll中有导出的利用静态调用没有什么问题的。
 
zhangchao_7622@hotmail.com
 
有没有朋友帮助我呀!!!
 
马上发,请查收
 
各位帮我,急!!!
 
你没收到吗?????<br>发到你的信箱中了
 
library dll;<br><br>{ Important note about DLL memory management: ShareMem must be the<br>&nbsp; first unit in your library's USES clause AND your project's (select<br>&nbsp; Project-View Source) USES clause if your DLL exports any procedures or<br>&nbsp; functions that pass strings as parameters or function results. This<br>&nbsp; applies to all strings passed to and from your DLL--even those that<br>&nbsp; are nested in records and classes. ShareMem is the interface unit to<br>&nbsp; the BORLNDMM.DLL shared memory manager, which must be deployed along<br>&nbsp; with your DLL. To avoid using BORLNDMM.DLL, pass string information<br>&nbsp; using PChar or ShortString parameters. }<br><br>uses<br>&nbsp; sharemem,&lt;&lt;注意这儿,如果用string型需引用这个单元<br>&nbsp; SysUtils,<br>&nbsp; Classes;<br><br>function getstr:string;<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp;result:='52free';<br>&nbsp; end;<br><br>{$R *.res}<br>&nbsp; exports getstr;<br>begin<br><br>end.
 
这是调用dll的工程文件的单元<br>program Project1;<br><br>uses<br>&nbsp; sharemem,&lt;&lt;注意这儿,同理<br>&nbsp; Forms,<br>&nbsp; dfd in 'dfd.pas' {Form1};<br><br>{$R *.res}<br><br>begin<br>&nbsp; Application.Initialize;<br>&nbsp; Application.CreateForm(TForm1, Form1);<br>&nbsp; Application.Run;<br>end.<br>
 
后退
顶部