替你改写一下。 function joinstr(str1:pchar;str2:pchar):pchar;stdcall;
var
len1,len2,i:integer;
begin
len1:=strlen(str1);
len2:=strlen(str2);
GetMem(Result, Len1 + len2 + 1);
StrPCopy(Result, str1);
StrCat(Result, str2);
end;
var
len1,len2,i:integer;
begin
len1:=strlen(str1);
len2:=strlen(str2);
GetMem(Result, Len1 + len2 + 1);
StrPCopy(Result, str1);
StrCat(Result, str2);
end;
解决方案 »
- delphi如何实现与android平台的通讯?
- 如何修改控件颜色?谢谢各位大佬!
- 一个很菜的问题,调试程序遇到的知道朋友来看看!在线等。。。UP 有分
- 关于hint的问题
- 最好的界面控件,up有分
- 如何在程序运行时显示设计的AdoConnection控件的数据库连接对话框??
- 请教一问题啊,delphi操作EXCEL表的问题!
- 如何使用MS Speech API 进行中文语句的朗读?
- 急--100分:如何用DELPHI动态添加控件?
- 如何保护自己的进程不在任务管理器里被强制结束?
- 请问调用什么函数去掉一个string中的空格???
- 我也装了DELPHI6,这控件越来越多,都有用处吗?我越学越没信心了!
使用AllocMem等函数先分配内存。
我改为
begin
getmem(txt1,255);
getmem(txt2,255);
moudle:=loadlibrary('unitestr.dll');
if moudle<>0 then
begin
edit3.text:='';
@joinstr:=getprocaddress(moudle,'joinstr');
if @joinstr<>nil then
begin
txt1:=strpcopy(txt1,edit1.text);
txt2:=strpcopy(txt2,edit2.text);
edit3.text:=strpas(joinstr(txt1,txt2));
end;
end;
freelibrary(moudle);
end;
后,还是报此行错
edit3.text:=strpas(joinstr(txt1,txt2));
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. }uses
SysUtils,
Classes;{$R *.RES}function JoinStr(Str1, Str2: PChar): PChar; stdcall;
begin
Result := PChar(string(Str1) + string(Str2))
end;exports
JoinStr;begin
end.unit Unit11;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;function JoinStr(Str1, Str2: PChar): PChar; stdcall; external 'library1.dll';implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
Edit3.Text := string(JoinStr(PChar(Edit1.Text), PChar(Edit2.Text)));
end;end.
但你那是静态调用假如我用loadlibrary、getprocaddress来动态调用dll该如何实现?
对了,定义有些小问题,改为:
Tjoinstr=function(var str1:pchar;str2:pchar):pchar;stdcall;
GetMem(txt2,Length(edit2.text) + 1);
txt1:=strpcopy(txt1,edit1.text);
txt2:=strpcopy(txt2,edit2.text);