1、用Delphi编写DLL,如果VB、VC++等想调用,必须使用PChar类型。String是一个挺有意思的类型,引进它主要是为了解决内存泄露的问题,有点类似VC++中的CString类型。给你两个API希望对你有所帮助:
function GetStrAllocSize(const S: string): Longint;
var
P: ^Longint;
begin
P := Pointer(S);
Dec(P, 3);
Result := P^ and not $80000000 shr 1;
end;
function GetStrRefCount(const S: string): Longint;
var
P: ^Longint;
begin
P := Pointer(S);
Dec(P, 2);
Result := P^;
end;