What about this:
Delphi-Quellcode:
function Foonction(Data: PWideChar; Buffer: PWideChar; lenBuffer: Cardinal): Cardinal; external 'StringDLL.dll';
var
Buffer: string;
BufferSize: DWORD;
begin
BufferSize := Foonction('bar', nil, 0);
if BufferSize > 0 then
begin
SetLength(Buffer, BufferSize);
Foonction('bar', PWideChar(Buffer), BufferSize);
end
else
Buffer := '';
ShowMessage(Buffer);
end;
But it would be better if you made lenBuffer a variable parameter. This way you can return the buffer size
and a return value.