04-26-2023, 01:16 PM
There's a couple issues. The big one is the lack of `Byval` on your `file_ptr` parameters to `fprintf()` and `fclose()`. Pass-by-reference is the default so QB64 will actually pass the address of the `_Offset` rather than the `_Offset` value itself, leading to the explosions you're encountering. If you instead use `byval file_ptr As _Offset` then 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 `_Offset` is an `intptr_t` so 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 Library` or (preferably) `Declare CustomType Library`, both of those cause QB64 to generate its own C++ definitions for the functions listed in the `Declare Library` section 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 Library` for any functions where it's possible for you to provide the correct types directly (like `fopen()`).
The other issues is the types in the C++ function definitions. `fprintf()` and `fclose()` take a `FILE *` as their first argument, but an `_Offset` is an `intptr_t` so 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 Library` or (preferably) `Declare CustomType Library`, both of those cause QB64 to generate its own C++ definitions for the functions listed in the `Declare Library` section 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 Library` for any functions where it's possible for you to provide the correct types directly (like `fopen()`).