Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-05

Calling C++ object

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi,

I am trying to call a C++ object which is in a dll from a Pascal interface unit as described in Rudy's Delphi corner: (http://rvelthuis.de/articles/articles-cppobjs.html). I use the inheritance method, making my C++ object a descendent from a Virtual ancestor.

I end up with run time errors in both fpc and the cross 64 bit compiler (my desired target is Win64):

error 210, (=R6025 - pure virtual function call)

However, the code works using Delphi. All my functions in my Pascal interface are 'virtual; stdcall; abstract; so the error makes sense, except that it works in Delphi.

I am wondering what are differences between Delphi and FPC that will not let me call C++ objects from DLL's? Or is there a command line switch I have missed that may help?

I use:
ppcrossx64 program_name.pas -vi -Sg -Si -Mfpc -OpATHLON64 -XD -Xs -B -Rintel -Mdelphi -TWin64 -Cr Thanks for any help with this.

Josh.

Reply by email

Jonas Maebe
to Unknown author
Show quoted text 9 lines
I am trying to call a C++ object which is in a dll from a Pascal interface unit as described in Rudy's Delphi corner: (http://rvelthuis.de/articles/articles-cppobjs.html ). I use the inheritance method, making my C++ object a descendent from a Virtual ancestor. I end up with run time errors in both fpc and the cross 64 bit compiler (my desired target is Win64): error 210, (=R6025 - pure virtual function call)

Run time error 211 is for abstract function calls (= "pure virtual" function calls). 210 = "Object not initialized". You have range checking (or -CR) turned on. In this case, FPC inserts a run time check before calling any method, which verifies that the object/class is actually of the type that you declared in the source code.

If you make a class instance point to a C++ class instance, that check will obvious fail.

However, the code works using Delphi.

It relies on the VMT of the Pascal and C++ classes having an identical layout. This may work with certain versions of certain C++ compilers on certain platforms with Delphi and might also work in FPC (with the same caveats), but it can break at any time and is simply a hack. I would strongly recommend against using this at all, let alone in production software.

Jonas

Reply by email