Porting code from FreeBasic problem
BlitzMax Forums/BlitzMax Programming/Porting code from FreeBasic problem
| ||
| Hello I am trying to port over Frank Dodds rather excellent Irrlicht wrapper for FreeBasic to Blitzmax however I have hit a snag with a particular form of function that returns a type from the dll. For example take this key input code. The relevant Freebasic code is as follows
wrapper code
TYPE IRR_KEY_EVENT
key as uinteger
direction as uinteger
flags as uinteger
END TYPE
declare function IrrReadKeyEvent alias "IrrReadKeyEvent" () as IRR_KEY_EVENT PTR
Program code
DIM KeyEvent as IRR_KEY_EVENT PTR
KeyEvent = IrrReadKeyEvent
My blitzmax code is like this:
wrapper code
Type IRR_KEY_EVENT
Field key:Int
Field direction:Int
Field flags:Int
End Type
Global _IrrReadKeyEvent:IRR_KEY_EVENT()"win32" = getprocaddress(lib_irrw,"IrrReadKeyEvent")
Function IrrReadKeyEvent:Irr_Key_Event()
Return _IrrReadKeyEvent()
End Function
program code
Local KeyEvent:IRR_KEY_EVENT = New IRR_KEY_EVENT
KeyEvent = IrrReadKeyEvent()
DebugLog "Keyevent "+KeyEvent.key +" "+keyevent.direction+" "+keyevent.flags
My code runs but KeyEvent doesn't appear to hold any values when a key is pressed as only zeros are printed out. This is a problem I am having for all functions that return or manipulate types. Any ideas what I need to do to make this work? Last edited 2011 |
| ||
| Doesn't seem to like byte ptr's in arrays either..sigh |
| ||
| I think passing types/classes from C++ to Bmax is difficult, since the padding and sizes is different. Usually what is done, is a "glue" file is created to handle the type/class in C++, then in that glue file, functions are created to handle the Getters, Setters for the type/class. *SOMETIMES* you can get the type to match the class, and then you can pass a BYTE PTR and cast the byte pointer in a type. Although, I must admit, it is not as reliable and can be frustrating. Better to use the C++ glue. Brucey's modules are a GREAT reference for how glue is used. You can also look at my Quicktime glue, but I think I use only one class. Last edited 2011 |
| ||
| G-Man also made a fully functional BMax Irrlicht wrapper, so you should consider that as well. |
| ||
| Yes I am aware of Gman's wrapper and N3xtd but these are both rather literal ports of the irrlicht functions whereas Frank Dodds makes things a little simpler and has some nifty additional functions added in. I guess there is no option but to investigate making a glue file but my knowledge of c is very limited. I'll check out some of Brucey's modules as suggested. Last edited 2011 |
| ||
| Oh sure, but I wasn't suggesting GMan's wrapper for you to use, but rather check how he glued the source files and BMax classes. I'm sure Brucey's are great reference too, but that wrapper deals specifically with Irrlicht. |
| ||
| I have made a little progress with the above problem and I can get key events without using any glue. However the C side of things is not so good. Can anyone tell me why this won't compile IrrlichtHeader.h
struct IrrVector
{
Float x;
Float y;
Float z;
};
IrrlichtHeader.cpp
import "IrrlichtHeader.h"
void GetScreenCoordinatesFrom3DPosition(struct IrrVector *vector, Int *x, Int *y)
{
HMODULE Module = LoadLibrary (_T("irrlichtwrapper.dll"));
If (Null == Module)
{
//Error
}
FARPROC addr;
addr = GetProcAddress (Module, _T("IrrGetScreenCoordinatesFrom3DPosition"));
If (Null == addr)
{
//Error
}
addr(x, y, &vector);
}
test program
Import "IrrlichtHeader.cpp"
Type IRR_VECTOR
Field x:Float
Field y:Float
Field z:Float
End Type
Extern
GetScreenCoordinatesFrom3DPosition(vector:IRR_VECTOR, x:Int, y:Int)
End Extern
Last edited 2011 |