Thema: Delphi How to - string in DLL

Einzelnen Beitrag anzeigen

Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.648 Beiträge
 
Delphi 11 Alexandria
 
#13

AW: How to - string in DLL

  Alt 19. Jun 2011, 22:25
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.
Sebastian Jänicke
AppCentral
  Mit Zitat antworten Zitat