没有指明参数调用类型 function kkk: String;stdcall; external 'Func.dll';
function kkk: String;stdcall; external 'Func.dll'; 我试了还是出错!
export function kkk: String;stdcall;
copy_paste(木石三):难道不能用String吗?
要用string 的话,就要在uses的地方第一个调用shellmem单元 如果你是用dllwizard建立的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, pass string information using PChar or ShortString parameters. }
DLL文件: Func.dll function kkk: PChar;stdcall;implemetation function kkk: PChar; begin Result:='1234'; end;调用时: function kkk: PChar;stdcall; external 'Func.dll';
哦,更正一下,你用的是静态调用,不用上面说的那样做!这样,你把你源程序中的 function kkk: String; external 'Project1.dll'; 放到 implementation 的下边!
把在dll中的函数原形的string也改成pchar 即都使用pchar而非string!
使用String[200]试一试。我觉得应该有用
function kkk:Pchar ; begin Result := Pchar('12345...'); end;************************************** function kkk: Pchar; external 'Project1.dll';Caption := kkk ;这样可以的
我试了还是出错!
function kkk: String;stdcall;
如果你是用dllwizard建立的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, pass string information
using PChar or ShortString parameters. }
function kkk: PChar;stdcall;implemetation
function kkk: PChar;
begin
Result:='1234';
end;调用时:
function kkk: PChar;stdcall; external 'Func.dll';
library Project1;uses
ShareMem, SysUtils, Classes;{$R *.res}function kkk: String;
begin
Result:='1234';
end;exports
kkk;begin
end.
/******************************/
/*************调用源程序*****************/
unit Unit1;interfaceuses
ShareMem, 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;
function kkk: String; external 'Project1.dll';implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
caption:=kkk;
end;end.
/******************************/
function kkk:pchar;
function kkk: String; external 'Project1.dll';
放到 implementation 的下边!
即都使用pchar而非string!
begin
Result := Pchar('12345...');
end;**************************************
function kkk: Pchar; external 'Project1.dll';Caption := kkk ;这样可以的