C file functions in QB64 ???
#3
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()
).
Reply


Messages In This Thread
C file functions in QB64 ??? - by Jack - 04-26-2023, 11:00 AM
RE: C file functions in QB64 ??? - by Jack - 04-26-2023, 11:34 AM
RE: C file functions in QB64 ??? - by DSMan195276 - 04-26-2023, 01:16 PM
RE: C file functions in QB64 ??? - by Petr - 04-26-2023, 01:25 PM
RE: C file functions in QB64 ??? - by Jack - 04-26-2023, 02:25 PM
RE: C file functions in QB64 ??? - by Kernelpanic - 04-28-2023, 05:02 PM
RE: C file functions in QB64 ??? - by Jack - 04-28-2023, 05:51 PM
RE: C file functions in QB64 ??? - by Jack - 04-28-2023, 06:50 PM
RE: C file functions in QB64 ??? - by Ultraman - 04-28-2023, 07:04 PM
RE: C file functions in QB64 ??? - by Kernelpanic - 04-28-2023, 07:50 PM
RE: C file functions in QB64 ??? - by DSMan195276 - 04-29-2023, 02:16 AM
RE: C file functions in QB64 ??? - by Kernelpanic - 04-29-2023, 06:58 PM



Users browsing this thread: 3 Guest(s)