<B>This command is for advanced users who know what they're doing!</B>
This command allows you to include C++ code directly within your GLBasic program. GLBasic stops being an easy programming language with the use of the INLINE command!
- Numbers are of type "DGInt". That's a 64bit double on a PC, a 32bit float on PocketPC.
- Strings are of type "DGStr". Strings are always 8bit ASCII. Conversion to unicode is done through GLBasic commands.
- A $ is replaced by _Str. So a$ is a_Str.
- You get a const char* from a DGStr with a_Str.c_str();
- You get a char* from a string with buffer size 'x' bytes: a_Str.GetStrData(x);
- All GLBasic functions have a parameter list: e.g. MOUSEWAIT( );
- A number array is of type DGIntArray
- A string array is of type DGArray<DGStr>. DGArray is a template class for DIM/REDIM. It only requires a ( ) and a = operator.
- Access arrays: a[x][y] becomes a(x,y)
- There is nothing defined! If you need a function, declare it.
- INLINE puts you in __GLBASIC__ namespace. If you leave it, restore it afterwards!
- GLBASIC_HWND() gives the HWND of the GLBasic main window.
- GETSUBADDRESS(const DGStr& name) returns a pointer to a SUB - analogous to CALLBYNAME. A SUB is of type: DGInt(*sub)();
- With get_sprite_texture(id), you can get the texture id needed for glBindTexture.
The most used feature of INLINE is the availability to load external functions from a DLL for their use in GLBasic. For this purpose some very convenient functions are provided:
// Loads the function "foo" from "my.dll" into the pointer: foo
void (__stdcall* foo)(int, char); // Declaration
DLLCALL("my.dll", "foo", (void**) &foo);
Have them load automatically:
// outside of functions:
// DECLARE(name, "dll", (parameters), return_type)
DECLARE(foo, "my.dll", (int, char), void);
// DECLARE_ALIAS(name, "dll", "real_name", (parameters), return_type)
DECLARE_ALIAS(foo, "my.dll", "foo@4", (int, char), void);
The parameters must be presented in round braces. You may find that the function name in the dll differs from the name of the prototype. In this case the DECLARE_ALIAS function can be used.
If a function has a __cdecl calling convention (thus, it's no __stdcall), simply append a _C to the DECLARE:
DECLARE_C(foo, "my.dll", (int, char), void);
DECLARE_C_ALIAS(foo, "my.dll", "foo@4", (int, char), void);
The DLL and the function will be loaded at the start of the program and released when closing it. You should make sure that the function can be loaded properly by testing:
// everything's fine
C = 41
PRINT "C="+C, 100, 100