Reputation: 777
I am currently having trouble importing a Delphi DLL dynamically. The Delphi DLL function is declared as here :
function TEST() : PChar; cdecl;
begin
Result := '321 Test 123';
end;
In C++ I am calling it this way:
typedef char *TestFunc(void);
TestFunc* Function;
HINSTANCE hInstLibrary = LoadLibrary("Test.dll");
if (hInstLibrary)
{
Function = (TestFunc*)GetProcAddress(hInstLibrary, "TEST");
if (Function)
{
printf("%s", Function());
}
}
The problem is that I am only receiving the first letter of the string. How can I tell C++ that the string is not ending after the first char?
Thanks
Upvotes: 2
Views: 2333
Reputation: 613481
You have two problems:
PAnsiChar
, if you want to match up against char*
.Your options to solve item 2:
CoTaskMemAlloc
and CoTaskMemFree
. Using a shared heap allows you to allocate in one module, and deallocate in the other.As a rule of thumb, always prefer option 1 if it can meet your needs.
Upvotes: 2