不好意思,没有仔细看代码。
我对代码修正了一下,现在可以了,修正的全部代码如下:
unit callMainU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, InterfaceU;
type
TPc = function: IFun
stdcall;
type
TForm1 = class(TForm)
edt1: TEdit;
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function CallProc(p: TPc): String;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
h: THandle;
// hello: function (sName: string): string;
PubFun : function: IFun
stdcall;
begin
h := LoadLibrary('stringDll.dll');
if h <> 0 then
try
PubFun := GetProcAddress(h, 'PubFun');
Caption := CallProc(PubFun);
//if PubFun <> nil then
// Caption := PubFun.SayHelloTo(PChar(edt1.Text));
// ShowMessage(StrPas(PubFun.SayHelloTo(PChar(edt1.Text))));
finally
FreeLibrary(h);
end;
end;
function TForm1.CallProc(p: TPc): String;
begin
Result := p.SayHelloTo(edt1.Text);
end;
end.