Using a C++ dll in delphi

Giganews Newsgroups
Subject:Using a C++ dll in delphi
Posted by: daniel raith (daniel.rai…@fiserv.com)
Date:Wed, 30 Sep 2009

The C++ dll declaration is

LPSTR ConvertName(char* firstname, char* middlename, char* lastname)

I'm trying to call it as such (pseudo code)

function MyConvertNameWrapper( aFirst, aMiddle, aLast: PChar): PChar;
begin
  Result := nil;
  LoadLibrary( DLL );
  try
    PROC := GetProcAddRess( DLLHandle, ProcName );
    if Assigned( PROC ) then
      StrLCopy( Result, PROC( PChar(First),PChar(Middle),PChar(Last) ) );
  finally
    FreeLibrary( DLLHandle );
  end;
end;

Is the StrLCopy the proper way to do this? Anything else I try either
blows up calling the PROC or corrupts my stack and blows up when I leave
  my wrapper method.

Replies