我下面的代码有什么问题,那们兄弟能解答一下?(100分)

  • 主题发起人 主题发起人 sxbing
  • 开始时间 开始时间
S

sxbing

Unregistered / Unconfirmed
GUEST, unregistred user!
library NumberToChinese;
uses
SysUtils,
Classes,Dialogs;

{$R *.RES}

Function FToC(Money:Double) :String ; Export ;
begin
Result := CurrToStr(Money) ;
end;

Exports
FToC ;

begin
end.
为什么我在下面的Unit中调用上央的DLL会出错》?????
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Function FToC(Number:Double):String;Stdcall;External 'NumberToChinese.Dll' Name 'FToC' ;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(FToC(56365)) ;
end;

end.
 
Function FToC(Money:Double) :String ; stdcall;
 
Function FToC(Money:Double) :String ; stdcall;
不对,不能返回 String;

procedure FToC(Money:Double; Value: PChar); stdcall;
var
s: String;
begin
s := CurrToStr(Money);
StrCopy (Value, PChar (s));
end;

用FToC时要给Value分Memory
var
Value: PChar;
begin
GetMem (Value, 255);
FToC(56365, Value);
ShowMessage(Value);
FreeMem (Value);
end;
 
我的目的是,通过一个DLL氢一个数字转化为字符串????
 
请看delphi创建dll时的说明:注意最后一句
Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, [red]pass string information
using PChar or ShortString parameters[/red]
.
 
可以传入一个PChar来得到结果
 
兩種方法:
1.改為:
Exports
FToC Name 'FToC' ;
2.改為:
Function FToC(Number:Double):String;Stdcall;External 'NumberToChinese.Dll';
即去掉Name 'FToC' ;

 
我是要在其它的语言中调用,所以所有的操作都要在delphi的DLL中处理完。。。。
 
多人接受答案了。
 
后退
顶部