Passing objects between BlitzMax and C++

BlitzMax Forums/BlitzMax Programming/Passing objects between BlitzMax and C++

Yog(Posted 2007) [#1]
Does anyone know if the following is possible:

Create a C++ object in a cpp file, then pass this object to a bmx file, and access it's methods and fields in the bmx file.

Also, the reverse:

Create a BlitzMax object in a bmx file, pass this object to a cpp file, and access it's methods and fields in the cpp file.

I can pass ints and floats between BlitzMax and C++, but am getting confused when it comes to passing objects.


GW(Posted 2007) [#2]
Check the docs under advanced topics -> interfacing with C


Gabriel(Posted 2007) [#3]
In short, no you can't operate on methods either way around. Because Blitz doesn't have method pointers and cannot use C classes with anything other than virtual methods.

You have to wrap C classes with functions which call those methods and then pass your class instance as a Byte Ptr.

To do it the other way around, you'd need BlitzMax wrapper functions which take a type instance and then call the method, but this is not GC safe, of course, so you have to have some mechanism of ensuring that BlitzMax keeps the objects and does not destroy them before you use them.


skidracer(Posted 2007) [#4]
There is an exception for calling methods of OLE style windows classes, check out pub.mod/directx.mod/d3d7.bmx for an example.

Also, for managing BiltzMax objects from C++ there are a few hints here for managing the reference counters etc. covered here.