07-25-2024, 05:30 AM
`Declare Library` is designed for calling external C and C++ functions, not QB64 functions. The `String` argument is passed as a `char *` in C++, not as the internal String representation (`qbs *`) that the QB64 runtime uses (this is what Luke was getting at). There's nothing you can do, it's just not going to work like you want. Array's aren't allowed either for a similar reason.
I would add that I personally wouldn't bother trying to use this for anything 'serious' as there's large problems you'll run into if you put non-trivial functions into the dll. The QB64 runtime (`libqb` and various other parts) ends up compiled both into your dll and the new exe you link against it. The result is roughly two separate instances of the runtime in your program which will not interact correctly. Even a simple `Print x` will not work from the dll, and lots of actions will probably cause your program to blow up. (Not to mention, the "runtime" is not always the same. We compile the runtime differently depending on the needs of your program so the runtime in the dll will likely not match the one used by the exe).
To make a dll like this you would need to make significant modifications to `qbx.cpp` along with the build logic so that the generated C++ functions get compiled separately from the runtime (and the runtime is excluded from the dll). That would get you closer to what you're looking for because then you could link against that `dll` and it would make use of the runtime provided by the exe (you'd still have the problem with `String`s and Arrays, but in theory `Print x` would work).
I would add that I personally wouldn't bother trying to use this for anything 'serious' as there's large problems you'll run into if you put non-trivial functions into the dll. The QB64 runtime (`libqb` and various other parts) ends up compiled both into your dll and the new exe you link against it. The result is roughly two separate instances of the runtime in your program which will not interact correctly. Even a simple `Print x` will not work from the dll, and lots of actions will probably cause your program to blow up. (Not to mention, the "runtime" is not always the same. We compile the runtime differently depending on the needs of your program so the runtime in the dll will likely not match the one used by the exe).
To make a dll like this you would need to make significant modifications to `qbx.cpp` along with the build logic so that the generated C++ functions get compiled separately from the runtime (and the runtime is excluded from the dll). That would get you closer to what you're looking for because then you could link against that `dll` and it would make use of the runtime provided by the exe (you'd still have the problem with `String`s and Arrays, but in theory `Print x` would work).