Dll的问题!(200分)

  • 主题发起人 主题发起人 ABA
  • 开始时间 开始时间
A

ABA

Unregistered / Unconfirmed
GUEST, unregistred user!
library Dll_1;<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; SysUtils,<br>&nbsp; Classes,system;<br><br>//{$R *.res}<br><br>function CurrChange(Amount: real): string;stdcall;<br>var<br>&nbsp; str,str1,str2:widestring;<br>&nbsp; j:integer;<br>begin<br>&nbsp; if (Amount&lt;0) or(Amount&gt;99999999.99) then<br>&nbsp; begin<br>&nbsp; &nbsp; currchange:=floattostr(Amount);<br>&nbsp; &nbsp; exit<br>&nbsp; end;<br>&nbsp; str1:='零千零佰零拾零万零千零佰零拾零圆零角零分';<br>&nbsp; str2:='零壹贰叁肆伍陆柒捌玖';<br>&nbsp; str:=floattostr(int(Amount*100));<br>&nbsp; for j:=1 to length(str) do<br>&nbsp; &nbsp; str1[19-2*length(str)+2*j]:=str2[(strtoint(str[j])+1)];<br><br>&nbsp; if (str1[7]='零') &nbsp;then &nbsp;str1[7]:=' ';<br>&nbsp; if (str1[15]='零') then &nbsp;str1[15]:=' ';<br><br>&nbsp; for j:=1 to length(str1) do<br>&nbsp; &nbsp; if str1[j]='零' then str1[j+1]:=' ';<br><br>&nbsp; if (str1[17]='零') and (str1[19]='零') then str1:=str1+'整';<br><br>&nbsp; if str1[17]='零' then str1[17]:=' ';<br>&nbsp; if str1[19]='零' then str1[19]:=' ';<br><br>&nbsp; for j:=0 to 6 do<br>&nbsp; &nbsp; if (str1[2*j+1]='零') and (str1[2*j+3]='零') then str1[2*j+1]:=' ';<br><br>&nbsp; str2:='';<br><br>&nbsp; for j:=1 to length(str1) do<br>&nbsp; &nbsp; str2:=str2+trim(str1[j]);<br><br>&nbsp; if str2[1]='零' &nbsp;then str2[1]:=' ';<br>&nbsp; str2:=trim(str2);<br>&nbsp; if str2[1]='万' &nbsp;then str2[1]:=' ';<br>&nbsp; str2:=trim(str2);<br>&nbsp; if str2[1]='零' &nbsp;then str2[1]:=' ';<br>&nbsp; str2:=trim(str2);<br>&nbsp; if str2[1]='圆' &nbsp;then str2[1]:=' ';<br>&nbsp; for j:=1 to length(str2)-1 do<br>&nbsp; if str2[j]='零' then<br>&nbsp; if (str2[j+1]='万') or (str2[j+1]='圆') then str2[j]:=' ' &nbsp; ;<br>&nbsp; str1:='';<br>&nbsp; for j:=1 to length(str2) do<br>&nbsp; str1:=str1+trim(str2[j]);<br>&nbsp; currchange:=str1;<br>end;<br><br>Exports<br>&nbsp; CurrChange;<br><br>begin<br>end.<br>上面的代码是DLL的。<br>我使用的时候,提示“无法定位程序到输入点CURRCHANGE于动态连接库DLL_1.DLL上”。<br>不知道是什么原因?大家帮帮忙?<br>
 
DLL_1.DLL不在当前目录
 
在当前目录,不是路径的问题。
 
试试看!<br>uses<br>&nbsp; ShareMem, &nbsp; &nbsp;//第一个引用的单元***记住<br><br>begin<br>&nbsp; DllApplication := Application;<br>&nbsp; DLLProc := @DLLUnloadProc;<br>end;
 
仔细看看最前面那一段注释,不要用string传递参数或者返值。
 
uses 之后加:<br>exports<br>&nbsp; CurrChange;
 
应该是你调用DLL时的格式不正确吧。检查一下<br>或者写出你调用的那个语句
 
我加了ShareMem还是不行呀。<br>这是我调用的源码<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>&nbsp; function CurrChange(Amount: real): string;stdcall;<br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>&nbsp; function CurrChange;External 'Dll_1.dll' name 'Currchange';<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; Temp:String;<br>begin<br>&nbsp; Temp:=Currchange(99.00);<br>&nbsp; //Temp:=IntToStr(Wode);<br>&nbsp; ShowMessage(Temp);<br>end;<br><br><br>end.<br>大家看看有什么错误!
 
哈哈,错误在这里:<br>&nbsp;function CurrChange;External 'Dll_1.dll' name 'Currchange';<br><br>'Currchange';函数名称不一样,注意大小写<br>改为: function CurrChange;External 'Dll_1.dll' name 'CurrChange';<br><br>给分吧,嘿嘿
 
你dll中的函数好象没有导出
 
To:wbtvc<br>&nbsp; &nbsp;确实是大小写的问题.谢谢你,还有大家。<br>是不是,DLL中用到STRING类型就必须用SHAREMEM
 
多人接受答案了。
 
后退
顶部