关于在DLL中的重载(300分)

影 子

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟无法实现在DLL中重载,贴上源码。编译通过,但代码也许本身就是错的。谢谢各位回复。

//DLL文件源码如下:
library Project;

uses
Unit2 in 'Unit2.pas';

{$R *.res}

exports
Test(str: pchar),
Test(i: integer);
begin
end.
//====
unit Unit2;

interface

uses
Windows, SysUtils;

procedure Test(str: pchar); stdcall;overload;
procedure Test(i: integer);stdcall;overload;

implementation

procedure Test(str: pchar); stdcall;overload;
begin
MessageBox(0,str,'first',MB_ICONERROR+MB_OK);
end;

procedure Test(i: integer);stdcall;overload;
begin
MessageBox(0,pchar(inttostr(i)),'second',MB_ICONERROR+MB_OK);
end;
end.

////==========程序文件内容
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, 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;

implementation
procedure Test(i: integer);stdcall;overload;external 'Project.dll';
procedure Test(str: pchar);stdcall;overload;external 'Project.dll';
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Test(23);
Test('23'); //此输出结果错误
end;

end.
 
将exports
Test(str: pchar),
Test(i: integer);
改为exports
Test(str: pchar) name strtest,
Test(i: integer) name inttest;
然后分别引用
 
你忽略了单引号。感谢答复。
 
顶部