Posts: 102
Threads: 28
Joined: Apr 2022
Reputation:
4
Would it be possible to create a DLL out of qb64 code to use in other Window languages ? I have seen huge DLL's so size should not matter or will it.
I have nothing in mind at this time. It's just a passing thought.
Posts: 422
Threads: 27
Joined: Apr 2022
Reputation:
26
don't forget to remove the -shared from the linker options so that QB64 can make proper executables
Posts: 2,157
Threads: 222
Joined: Apr 2022
Reputation:
102
I remember making fake dll's with QuickBASIC YOu had to break up large apps back then, so at one point, I just tweaked a couple of things and renamed some of the compiled .exe extensions as .dll. Worked like a charm. I'd like to say I miss those days... but I really don't!
Pete
Posts: 102
Threads: 28
Joined: Apr 2022
Reputation:
4
Interesting. When I actually have a use or somebody I know does. I can refer back to this thread.
Thanks
Posts: 422
Threads: 27
Joined: Apr 2022
Reputation:
26
07-24-2024, 07:09 AM
(This post was last modified: 07-24-2024, 07:17 AM by Jack.)
I tried the simple example with double and _Float and they work ok but I could not get a function or sub that returns or modifies a string to work, after a few seconds it silently crashes, if I find a solution to that I will post it here
<edit> changing the function and its parameters to a different type say from long to double will also give a different mangled function name by the C++ compiler
and different C++ compilers could possibly mangle names differently, hopefully the g++ compiler will produce the same name mangling across versions
Posts: 35
Threads: 4
Joined: Apr 2022
Reputation:
14
You won't be able to pass strings as you expect. QB64 functions expect to receive a string descriptor, but DECLARE LIBRARY functions are sent a pointer to the character data.
You could have your function receive an _OFFSET, but you won't be allowed to change the length of the string (and you will need to supply the length as a separate parameter).
Posts: 303
Threads: 10
Joined: Apr 2022
Reputation:
44
`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).