你好像把问题复杂化了,另外字符串参数最好用pchar类型,而不要用string.具体原因
如下:
{ 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的资料你可以到
http://nihao.dlut.edu.cn/web/book/去找一下
上面的一本<<Delphi 5编程实例与技巧 >> chap6 有关于dll入门的一些介绍
还是给你一个简单例子吧:
==============
dll source
==============
library mydll;
uses
SysUtils,
Classes;
{$R *.RES}
function Tspace_dot(str
char):integer;stdcall;
begin
result := length(str);
end;
function Tdeal_dot(str
char)
char; stdcall;
begin
result := str;
end;
exports
Tspace_dot index 1,
Tdeal_dot index 2;
begin
end.
===============
load dll demo
===============
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function Tspace_dot(str
char):integer;stdcall;external'mydll.dll';
function Tdeal_dot(str
char)
char;stdcall;external'mydll.dll';
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text := inttostr(Tspace_dot('abcd'));
edit2.text := Tdeal_dot('abcd');
end;
end.