views:

108

answers:

1

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 try. I tried various calling conventions, playing with underscores. even creating a .c wrapper for the .cpp code (but then the .c wrapper doesn't "see" any .cpp symbols). I'm about to give up and use DLLs. Any suggestions?

+2  A: 

You have run into a limitation of the compiler.

These two articles cover your options in fairly good detail:

Robert Love