QB64 Phoenix Edition
C++ in QB? - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: C++ in QB? (/showthread.php?tid=2735)



C++ in QB? - CletusSnow - 05-26-2024

I think I read somewhere that it is possible to use C++ code within a QB program. But unfortunately I can't find any information about it.
Is it possible, and if so, how?


RE: C++ in QB? - BSpinoza - 05-26-2024

https://qb64phoenix.com/qb64wiki/index.php/Libraries


RE: C++ in QB? - CletusSnow - 05-26-2024

Thank you for your reply, but I think that is not what I mean.
I was thinking of a possibility similar to using JavaScript within HTML, and without using Libraries.


<HTML>
...some html...

<Script language: JavaScript>
...some javascript...
</Script>

...more html...
</HTML>


RE: C++ in QB? - RhoSigma - 05-26-2024

It's pretty easy:

1. Place your C/C++ functions in a *.h file
2. On the QB64 side bind your functions using a DECLARE LIBRARY block by referencing the *.h file (important: name the file without .h extension)
3. Use the functions on the QB64 as per the declarations.

If you get compiler errors, try to fix it on the C/C++ side, most issues arise with incorrect/unknown typing or namespaces. So try to limit yourself to <stdint.h> types and add namespace prefixes to functions when required (eg. std :: somefunction).

For an easy example see my RegEx implementation.

More stuff to examine in my Libraries collection, especially the Base64, Md5, Des56, Sha2 and standard library stuff.


RE: C++ in QB? - CletusSnow - 05-26-2024

Ok, thanks a lot. I See. And I need more Coffee. Sometimes I feel like a pirat with two eye patches...


RE: C++ in QB? - Kernelpanic - 05-26-2024

(05-26-2024, 04:11 PM)CletusSnow Wrote: I think I read somewhere that it is possible to use C++ code within a QB program. But unfortunately I can't find any information about it.
Is it possible, and if so, how?
For example, it goes like this:

The Basic file (Both files in the same ordner):
Code: (Select All)

Option _Explicit

'In QB64 mit "Declare Library" wie angegeben
Declare Library "D:\Lab\QuickBasic64\Extern-nicht-Basic\Basic-ruft-C\bfibonacci"
  Function fibo& (ByVal N As Integer)
End Declare

Dim As Integer N, rueckgabe
Dim As Single zeitstart, zeitende

Timer On

Cls
Locate 3, 3
Input "Berechnet die Fibonacci-Zahl von: ", N

zeitstart = Timer

Locate 5, 3
rueckgabe = fibo&(N%)
If rueckgabe = -1 Then
  Print "Eingabe zu gross!"
  Sleep: System
Else
  Print Using "Die Fibonacci-Zahl von ## = ###,########"; N; fibo&(N%)
End If

zeitende = Timer

Locate 7, 3
Print Using "Sekunden: ##.#### "; zeitende - zeitstart

End

The C-file ( bfibonacci.h):
Code: (Select All)

#include <stdio.h>
#include <stdlib.h>

long fibo(int n)
{
long x, y;
int i;

//Um bei 3 eine Anzeige von: 1 2 3 zu erreichen
x = y = i = 1;
if (n == 0 || n == 1)
{
return(n);
}
if (n > 40)
{
return(-1);
//sonst Überlauf
}
else while (i < n)
{
x = x + y; y = x - y; i++;
}
return(x);
}



RE: C++ in QB? - grymmjack - 05-27-2024

(05-26-2024, 05:29 PM)CletusSnow Wrote: Ok, thanks a lot. I See. And I need more Coffee. Sometimes I feel like a pirat with two eye patches...

LOL! Speaking of coffee, your humor made me nearly spit mine out all over my keyboard.

Thanks for that, and good luck!