12-07-2023, 01:31 PM
Basically, the idea is to create a ".h" file and write C / C++ functions in them that are QB64 friendly.
See:
DECLARE LIBRARY - QB64 Phoenix Edition Wiki
C Libraries - QB64 Phoenix Edition Wiki
Here is a short example that should print "1".
mybasapp.bas
myclib.h
There are many rules. However, a few of them are as follows:
I generally do a lot of mixed-language programming.
See a740g/Toolbox64: A740g's collection of libraries for QB64-PE (github.com) for some examples, and a740g/raylib-64: QB64-PE bindings for raylib (a simple and easy-to-use library to learn videogames programming) (github.com) for something a little more advanced.
See:
DECLARE LIBRARY - QB64 Phoenix Edition Wiki
C Libraries - QB64 Phoenix Edition Wiki
Here is a short example that should print "1".
mybasapp.bas
Code: (Select All)
OPTION _EXPLICIT
DECLARE LIBRARY "myclib"
FUNCTION bar& (BYVAL a AS LONG, BYVAL b AS LONG)
END DECLARE
PRINT foo(325, 2)
END
FUNCTION foo& (a AS LONG, b AS LONG)
foo = bar(a, b)
END FUNCTION
myclib.h
Code: (Select All)
#pragma once
int bar(int a, int b)
{
return a % b;
}
There are many rules. However, a few of them are as follows:
- Ensure the C/C++ library file has the extension ".h" and do not specify the extension in the DECLARE LIBRARY line.
- Ensure the C header library is in the same directory as your ".bas" source or in a relative directory as specified in the DECLARE LIBRARY line.
- Be careful about when to pass arguments to C functions by value or by reference.
- Be careful about the data types that are used (the links above have a comparison table)
I generally do a lot of mixed-language programming.
See a740g/Toolbox64: A740g's collection of libraries for QB64-PE (github.com) for some examples, and a740g/raylib-64: QB64-PE bindings for raylib (a simple and easy-to-use library to learn videogames programming) (github.com) for something a little more advanced.