How to connect Delphi with C ++?

cpp.cpp

extern "C"
char* GetText()
{
  return "Hello, world!";
}

delphi.dpr

{$APPTYPE CONSOLE}

{$LINK 'cpp.obj'}
function _GetText: PChar; cdecl; external;

begin
  WriteLn(_GetText);
end.

I can't get this to work, no matter what. I tried various calling conventions playing with underscores. even creating a .c wrapper for the .cpp code (but then the .c wrapper does not "see" any .cpp characters). I am going to refuse and use DLLs. Any suggestions?

+3
source share
1 answer

You have encountered a compiler restriction.

These two articles detail your options:

+2
source

Source: https://habr.com/ru/post/1748924/


All Articles