Delphi DLL 函数原型:function MyFun(key:PChar;var name:PChar):boolean;stdcall;export;
begin
name := StrAlloc(StrLen(key) + 1);
StrCopy(name,key);
result := TRUE;
end;PB申明:
function boolean MyFun(string key,ref string name) Library "MyFun.dll"PB调用:
string ls_key,ls_name
ls_key = "ME"
MyFun(ls_key,ls_name)
MessageBox(ls_key,ls_name)问:提示内容却不是"ME"了,为什么?
begin
name := StrAlloc(StrLen(key) + 1);
StrCopy(name,key);
result := TRUE;
end;PB申明:
function boolean MyFun(string key,ref string name) Library "MyFun.dll"PB调用:
string ls_key,ls_name
ls_key = "ME"
MyFun(ls_key,ls_name)
MessageBox(ls_key,ls_name)问:提示内容却不是"ME"了,为什么?
function StrPCopy(Dest: PChar; const Source: string): PChar;
Description
StrPCopy copies a Pascal-type string Source into a null-terminated string Dest. It returns a pointer to Dest.
StrPCopy does not perform any length checking. The destination buffer must have room for at least Length(Source)+1 characters.另外也有这种可能: