04-26-2023, 01:16 PM
There's a couple issues. The big one is the lack of
The other issues is the types in the C++ function definitions.
Byvalon your
file_ptrparameters to
fprintf()and
fclose(). Pass-by-reference is the default so QB64 will actually pass the address of the
_Offsetrather than the
_Offsetvalue itself, leading to the explosions you're encountering. If you instead use
byval file_ptr As _Offsetthen it might work.
The other issues is the types in the C++ function definitions.
fprintf()and
fclose()take a
FILE *as their first argument, but an
_Offsetis an
intptr_tso you cannot pass that as a
FILE *without a cast (and there's no way to insert the cast as QB64 won't do it for you). The solution here is to use either
Declare Dynamic Libraryor (preferably)
Declare CustomType Library, both of those cause QB64 to generate its own C++ definitions for the functions listed in the
Declare Librarysection based on the types you define, so the types you provide will always match. The big catch with this is that it also means there will be no type-checking by C++ to ensure you're actually passing the right thing, so it's best to use regular
Declare Libraryfor any functions where it's possible for you to provide the correct types directly (like
fopen()).