Passing a BMX object to a C++ DLL

BlitzMax Forums/BlitzMax Programming/Passing a BMX object to a C++ DLL

JoshK(Posted 2010) [#1]
Let's say I have a BlitzMax object with these members:

Type TVec3
Field x:Float
Field y:Float
Field z:Float
EndType

The C++ function is like this:

GetSomething(Vec3* v)
{
v->x=1
v->y=2
v->z=3
}

Here's the declaration of the function in BMX:
Extern "c"
Function GetSomething(v:TVec3)
EndExtern

What is the correct way to make these work together?

Last edited 2010


skidracer(Posted 2010) [#2]
Your c++ function has no calling convention nor is in fact valid C++.

You need to settle on a calling convention, typically cdecl which means adding extern "C" lines to both source files.


JoshK(Posted 2010) [#3]
I'm using cdecl. I use lots of other commands between the two languages. I just need more information on passing objects.


ProfJake(Posted 2010) [#4]
Not exactly sure if this works, since I don't have BMax at hand right now.
But I recently did something like this which was fine:

Extern
    Function GetSomething(vec:Float Ptr)
End Extern

Local vec:TVec3 = TVec.create(1.0, 1.0, 1.0)
GetSomething(Varptr vec.x) ' x must be the first field


But if you are serious about this, then take a look at how BBObject works in brl.mod/brl.blitz/blitz_object.c. Then you can extend it and everything is shiny =D

Last edited 2010


JoshK(Posted 2010) [#5]
I've had it working using a Byte Ptr, which is basically the same as what you posted, but I wanted to see if there was any official word on this.


beanage(Posted 2010) [#6]
if there was any official word on this

Am I hearing a slight glitch of cynicism here? :P


JoshK(Posted 2010) [#7]
If there is any potential for problems using this approach I would like to know about it. Is that unreasonable?