Using a freebasic dll in c++

New to FreeBASIC? Post your questions here.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using a freebasic dll in c++

Post by dodicat »

Yes, I gave it a try
OK - nice
I remember using graphics.h and WinBgIm.h for C years ago.
(what a carry on to draw a circle!)

But it is so easy with a freebasic .dll.
Any C enthusiast would score from the freebasic graphics capabilities.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Using a freebasic dll in c++

Post by Boromir »

dodicat wrote:Yes, I gave it a try
OK - nice
I remember using graphics.h and WinBgIm.h for C years ago.
(what a carry on to draw a circle!)

But it is so easy with a freebasic .dll.
Any C enthusiast would score from the freebasic graphics capabilities.
I agree.
I've been trying to learn c++ lately but without a way to do graphics it was hard. I got sdl setup but I couldn't stand that. Now with fbgfx in c++, just testing the wrapper I've learned a good bit of stuff about c++. It's actually not a bad language with fbgfx.
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Using a freebasic dll in c++

Post by St_W »

MrSwiss wrote:@Boromir,

please ignore St_W's comment. In the first sentence are 2 grave errors:
  • 1) the lib is written in FB (not C) -- and --
    2) Yes, the C#-wrapper has to be re-done, for C++ (or straight C).
I was talking about the fbgfx library, that is integrated in FreeBasic, which is implemented in plain C - no FreeBasic and no C#
See https://github.com/freebasic/fbc/tree/m ... rc/gfxlib2
No wrapper library (like fbgfx#) is needed to use it.
But obviously it seems some other library exists that has a similar name?
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using a freebasic dll in c++

Post by dodicat »

Boromir
Here is a way for byref mouse C++

Code: Select all

'one.bas  for c++
'compile with -dll
extern  "C++"
Sub screen1 (Byval X As Integer, Byval Y As Integer,xres as integer,yres as integer,b as integer) EXPORT
  Screenres xres,yres,b
  SCREENCONTROL(100, X, Y)
End Sub

function rgbcolor(r as integer,g as integer,b as integer) as uinteger export
    return rgb(r,g,b)
end function

Sub printstring (x as integer,y as integer, text As zString ptr,c as uinteger) EXPORT
 draw string (x,y),*text,c
End Sub

sub printdbl(n as double) export
    print n
    end sub

sub line1(x1 as integer,y1 as integer,x2 as integer,y2 as integer,c as uinteger) EXPORT
    line (x1,y1)-(x2,y2),c
end sub

sub sleep1(t as integer) export
    sleep t
end sub

function randoms(n as integer) as double export
    return rnd*n
    end function

sub circlefill1(x1 as integer,_
    y1 as integer,_
    rad as integer,_
    c as uinteger) export
    circle (x1,y1),rad,c,,,,f
end sub

sub circle1(x1 as integer,_
    y1 as integer,_
    rad as integer,_
    c as uinteger) export
    circle (x1,y1),rad,c
end sub

sub pset1(x1 as double,y1 as double,c as uinteger,im as any pointer=0) EXPORT
    pset im,(x1,y1),c
end sub
sub clearscreen1 export
    cls
end sub
sub endkey1 export
    if inkey=chr(27) then end
end sub
sub screenlock1 export
    screenlock
end sub
sub screenunlock1 export
    screenunlock
end sub
sub getmouse1( mx as integer ptr, my as integer ptr, mw as integer ptr, mb as integer ptr) export
    getmouse(*mx,*my,*mw,*mb)
end sub
sub locate1(x as integer,y as integer) export
    locate x,y
end sub

Function framecounter() As Integer export
    dim as double t2=timer
    Static As Double t3,frames,answer
    frames=frames+1
    If (t2-t3)>=1 Then
        t3=t2
        answer=frames
        frames=0
    End If
    Return answer
End Function

end extern
 
and a tester c++ code

Code: Select all

#include<stdio.h>
#include <stdint.h>
#include<stdlib.h>
 extern void  screen1(int x, int y,int xres,int yres,int b);
 extern void  printstring (int x,int y,char* text,unsigned int c);
 extern void printdbl(double n);
 extern void circlefill1(int x1,int y1,int rad,unsigned int c);
 extern void line1(int x1,int y1,int x2,int y2,unsigned int c);
 extern unsigned int rgbcolor(int r,int g,int b);
 extern void screenlock1();
 extern void screenunlock1();
 extern void sleep1(int n);
 extern double randoms(int n);
 extern void clearscreen1();
 extern void endkey1();
 extern void locate1(int x,int y);
 extern int framecounter();
 extern void getmouse1(int *mx,int *my,int *mw,int *mb);
 



 int h= 1,fps;
 int mx,my,mw,mb;


 int main(void)

 {
 screen1(50,20,1000,768,32);
 while (h>0)
 {
 	getmouse1(&mx,&my,&mw,&mb);
   // h++;
    screenlock1();
 //clearscreen1();
 fps=framecounter();
 printstring(0,100,"Mouse",rgbcolor(255,255,255));
 locate1(15,1);
 printdbl(mx);
 printdbl(my);
 printdbl(mw);
 printdbl(mb);
 printstring(50,10,"Hello, Press escape key to end",rgbcolor (255,200,0));
circlefill1(50+rand() % 950,50+rand() % 600,5+rand() % 70,rgbcolor(rand() % 255,rand() % 255,rand() % 255));
//line1(20,20,randoms(900),randoms(700),rgbcolor(0,200,0));
screenunlock1();
sleep1(1);
endkey1();
}


 system ("pause");
}
  
I have to upgrade my lib code, the printouts are crude.
But that's another day.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Using a freebasic dll in c++

Post by Boromir »

dodicat wrote:Boromir
Here is a way for byref mouse C++
Nice, thanks!
I'm still not very good with pointers. :)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using a freebasic dll in c++

Post by dodicat »

Thanks Boromir.
I have got a bouncing ball with the framerate regulated at 60 fps in C++.
But I don't like Dev C++ ide.
I am not used to code completion, I am rubbing out more text than I am typing.
Cheers for now.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Using a freebasic dll in c++

Post by Boromir »

dodicat wrote:Thanks Boromir.
I have got a bouncing ball with the framerate regulated at 60 fps in C++.
But I don't like Dev C++ ide.
I am not used to code completion, I am rubbing out more text than I am typing.
Cheers for now.
I'm using Geany on Linux and Sublime Text on Windows.

Here is some performance test results.

General graphics test with a 640x480 image put.
With "sleep 1"
Freebasic=660 fps
C++=653 fps
Cpu hogging without "sleep 1"
Freebasic=3300 fps
C++=3000 fps

Program with 307200 calls to pset(overhead becomes noticeable)
With "sleep 1"
Freebasic=65 fps
C++=48 fps
Without "sleep 1"
Freebasic=70 fps
C++=54 fps
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Using a freebasic dll in c++

Post by BasicCoder2 »

So you can use the freebasic graphic library with C++?
Is there any tutorial for this?

I used to write all my programs with TurboC on my old DOS machines where you could access the graphic card directly and even dabbled with C++ and OOP using the Dev C++ ide and not so long ago using the CODE::BLOCKS editor. However the hassle of trying and failing to link a graphics library using code::blocks I gave up. I managed to link SDL to Dev CPP ide using a DevPak which automated the process.

What is it you want to do with C that you aren't able to do with FreeBASIC?
.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using a freebasic dll in c++

Post by dodicat »

I find straightforward C/C++ not too hard to code after using freebasic.
There are many similarities.
C and C++ use libraries extensively.
But it is hard to find a simple graphics library.
Cairo and such bloats are a collection of dll's (I think >5 for Cairo)
If you have some spare time you could try this out.
Three files.
32 bit.
file 1 -- one.bas. to be compiled -dll to provide the library
file 2 A C++ file. It is quite easy to include the above library with Dev C++
file 3 -- a freebasic file including the same library.

file 1

Code: Select all

'one.bas --- a dll for C++ or FreeBASIC
'compile with -dll
extern  "C++"
Sub screen1 (Byval X As Integer, Byval Y As Integer,xres as integer,yres as integer,b as integer) EXPORT
  Screenres xres,yres,b
  SCREENCONTROL(100, X, Y)
End Sub

sub clearcolor(c as uinteger) export
    color ,c
    cls
    end sub

function rgbcolor(r as integer,g as integer,b as integer) as uinteger export
    return rgb(r,g,b)
end function

Sub drawstring (x as integer,y as integer, text As zstring ptr,c as uinteger) EXPORT
 draw string (x,y),*text,c
End Sub

sub printdbl(n as double,flag as integer=0) export
    select case as const flag
    case 0:print n
    case 1:print n,
    case 2:print n;
    case else
        print n
        end select
    end sub

sub line1(x1 as integer,y1 as integer,x2 as integer,y2 as integer,c as uinteger) EXPORT
    line (x1,y1)-(x2,y2),c
end sub

sub sleep1(t as integer) export
    sleep t 
end sub

sub waitkey() export
    sleep
end sub

function randoms(n as integer) as double export
    return rnd*n
    end function

sub circlefill1(x1 as integer,_
    y1 as integer,_
    rad as integer,_
    c as uinteger) export
    circle (x1,y1),rad,c,,,,f
end sub

sub circle1(x1 as integer,_
    y1 as integer,_
    rad as integer,_
    c as uinteger) export
    circle (x1,y1),rad,c
end sub

sub pset1(x1 as double,y1 as double,c as uinteger,im as any pointer=0) EXPORT
    pset im,(x1,y1),c
end sub

sub clearscreen1 export
    cls
end sub

sub endkey1 export
    if inkey=chr(27) then end
end sub

sub screenlock1 export
    screenlock
end sub

sub screenunlock1 export
    screenunlock
end sub

sub getmouse1( mx as integer ptr, my as integer ptr, mw as integer ptr, mb as integer ptr) export
    getmouse(*mx,*my,*mw,*mb)
end sub
sub locate1(x as integer,y as integer) export
    locate x,y
end sub

Function framecounter() As Integer export
    dim as double t2=timer
    Static As Double t3,frames,answer
    frames=frames+1
    If (t2-t3)>=1 Then
        t3=t2
        answer=frames
        frames=0
    End If
    Return answer
End Function

Function regulate( MyFps As integer, fps As integer ptr) As integer export
    Static As Double timervalue,lastsleeptime,t3,frames
    frames+=1
    If (Timer-t3)>=1 Then t3=Timer:*fps=frames:frames=0
    Var sleeptime=lastsleeptime+((1/myfps)-Timer+timervalue)*1000
    If sleeptime<1 Then sleeptime=1
    lastsleeptime=sleeptime
    timervalue=Timer
    Return sleeptime
End Function

end extern
 
file 2

Code: Select all


// dev c++
// library command -lone
#include<new>
#include<math.h>
//library procedures needed
 extern void  screen1(int x, int y,int xres,int yres,int b);
 extern void  drawstring(int x,int y,char* text,unsigned int c);
 extern void printdbl(double n,int flag);
 extern void circlefill1(int x1,int y1,int rad,unsigned int c);
 extern void circle1(int x1,int y1,int rad,unsigned int c);
 //extern void line1(int x1,int y1,int x2,int y2,unsigned int c);
 extern unsigned int rgbcolor(int r,int g,int b);
 extern void screenlock1();
 extern void screenunlock1();
 extern void sleep1(int n);
 extern double randoms(int n);
 extern void clearscreen1();
 extern void endkey1();
 extern void locate1(int x,int y);
 //extern int framecounter();
 extern void getmouse1(int *mx,int *my,int *mw,int *mb);
 extern int regulate(int myfps,int *fps);
 extern void clearcolor(unsigned int c);
 
struct ball
{
	float x;
	float y;
	float dx;
	float dy;
	unsigned int col;
} ;

// globals
struct ball* b[3]={new ball,new ball,new ball};
 int fps,sleeptime;
 int mx,my,mw,mb;


// procedures
void move(struct ball* b[])
{
		for (int n=0;n<3;n++)
		{
b[n]->x+=b[n]->dx;
b[n]->y+=b[n]->dy;
}
}

void edges(struct ball* b[])
{
	int r=50;
	for (int n=0;n<3;n++)
	{

	if(b[n]->x<r) {
 		b[n]->dx=-b[n]->dx;
	 };
	 if(b[n]->x>1000-r){
 		b[n]->dx=-b[n]->dx;
	 };
	 if(b[n]->y<r){
 		b[n]->dy=-b[n]->dy;
	 };
	 if(b[n]->y>768-r){
 		b[n]->dy=-b[n]->dy;
	 };	
}

}

void draw(struct ball* b[])
{
	for (int n=0;n<3;n++)
	{	
circlefill1(b[n]->x,b[n]->y,50,b[n]->col);
circle1(b[n]->x,b[n]->y,50,rgbcolor(255,255,255));

}
}


void BallCollisions(struct ball* b[])
{
float L,impulsex,impulsey,dot,impactx,impacty;           
            for(int n1=0;n1<3;n1++)
                {
                for(int n2=n1+1;n2<3;n2++)
                    {
            L=sqrt( (b[n1]->x-b[n2]->x)*(b[n1]->x-b[n2]->x) + (b[n1]->y-b[n2]->y)*(b[n1]->y-b[n2]->y));
          
            if (L<100)     // Then
                {
                 impulsex=(b[n1]->x-b[n2]->x)/L;
                 impulsey=(b[n1]->y-b[n2]->y)/L;
                //In case of overlap circles, reset to non overlap positions
                b[n1]->x=b[n2]->x+100*impulsex;
                b[n1]->y=b[n2]->y+100*impulsey;
                 impactx=b[n1]->dx-b[n2]->dx;
                 impacty=b[n1]->dy-b[n2]->dy;
                 dot=impactx*impulsex+impacty*impulsey;
                b[n1]->dx-=dot*impulsex;
                b[n1]->dy-=dot*impulsey;
                b[n2]->dx+=dot*impulsex;
                b[n2]->dy+=dot*impulsey;
                }
            }
        }
    
    }

 int main(void)
//set up balls
 {
 	b[0]->x=100;
 	b[0]->y=100;
 	b[0]->dx=5.2;
 	b[0]->dy=3.2;
 	b[0]->col=rgbcolor(0,100,200);
 	
 	b[1]->x=600;
 	b[1]->y=200;
 	b[1]->dx=-5.2;
 	b[1]->dy=3.2;
 	b[1]->col=rgbcolor(200,100,0);
 	
 	
 	b[2]->x=700;
 	b[2]->y=500;
 	b[2]->dx=-1.2;
 	b[2]->dy=3.2;
 	b[2]->col=rgbcolor(0,200,0);
 	
 screen1(50,20,1000,768,32);
 clearcolor(rgbcolor(0,0,100));
 while (1)
 {
 
 	move(&b[0]);
 	edges(&b[0]);
 	BallCollisions(&b[0]);
	 
 	//getmouse1(&mx,&my,&mw,&mb);
 	
    screenlock1();
 clearscreen1();
 draw(&b[0]);
 
 
 drawstring(50,10," Press escape key to end",rgbcolor (255,200,0));
 drawstring(0,55,"framerate",rgbcolor(0,200,0));
 locate1 (8,11);
 printdbl(fps,0);

screenunlock1();
sleeptime=regulate(65,&fps);
sleep1(sleeptime);
endkey1();
}

 delete [] b;
}
  
file 3

Code: Select all


'freebasic using one.dll
#undef long
#undef ulong
#define long integer
#define ulong uinteger
#inclib "one"
extern "C++"

declare sub screen1(byval x as long, byval y as long, byval xres as long, byval yres as long, byval b as long)
declare sub drawstring(byval x as long, byval y as long, byval text as zstring ptr, byval c as ulong)
declare sub printdbl(byval n as double, byval flag as long)
declare sub circlefill1(byval x1 as long, byval y1 as long, byval rad as long, byval c as ulong)
declare sub circle1(byval x1 as long, byval y1 as long, byval rad as long, byval c as ulong)
declare function rgbcolor(byval r as long, byval g as long, byval b as long) as ulong
declare sub screenlock1()
declare sub screenunlock1()
declare sub sleep1(byval n as long)
declare function randoms(byval n as long) as double
declare sub clearscreen1()
declare sub endkey1()
declare sub locate1(byval x as long, byval y as long)
declare sub getmouse1(byval mx as long ptr, byval my as long ptr, byval mw as long ptr, byval mb as long ptr)
declare function regulate(byval myfps as long, byval fps as long ptr) as long
declare sub clearcolor(byval c as ulong)
end extern

type ball
	x as single
	y as single
	dx as single
	dy as single
	col as ulong
end type

dim shared as ball ptr  b:b=new ball[3]
dim shared fps as long
dim shared sleeptime as long
dim shared mx as long
dim shared my as long
dim shared mw as long
dim shared mb as long

 sub move(byval b as ball ptr )
    for n as integer=0 to 2
	b[n].x+=b[n].dx:b[n].y+=b[n].dy
    next n
end sub

 sub edges(byval b as ball ptr )
	dim r as long = 50
    for n as integer=0 to 2
	if(b[n].x<r) then b[n].dx=-b[n].dx
     if(b[n].x>1000-r)then b[n].dx=-b[n].dx
    if(b[n].y<r)then b[n].dy=-b[n].dy
    if(b[n].y>768-r)then b[n].dy=-b[n].dy
    next n
end sub

 sub _draw(byval b as ball ptr )
     for n as integer=0 to 2
	circlefill1(b[n].x,b[n].y,50,b[n].col)
    circle1(b[n].x,b[n].y,50,rgbcolor(255,255,255))
    next n
end sub

 sub BallCollisions(byval b as ball ptr )
	dim L as single
	dim impulsex as single
	dim impulsey as single
	dim dot as single
	dim impactx as single
	dim impacty as single
    for n1 as integer=0 to 2
        for n2 as integer=n1+1 to 2
	  L=sqr( (b[n1].x-b[n2].x)*(b[n1].x-b[n2].x) + (b[n1].y-b[n2].y)*(b[n1].y-b[n2].y))
      if (L<100) then 
       impulsex=(b[n1].x-b[n2].x)/L
       impulsey=(b[n1].y-b[n2].y)/L
       b[n1].x=b[n2].x+100*impulsex
       b[n1].y=b[n2].y+100*impulsey
       impactx=b[n1].dx-b[n2].dx
       impacty=b[n1].dy-b[n2].dy
       dot=impactx*impulsex+impacty*impulsey
       b[n1].dx-=dot*impulsex
       b[n1].dy-=dot*impulsey
       b[n2].dx+=dot*impulsex
       b[n2].dy+=dot*impulsey
   end if
next n2
next n1

end sub

function main() as long
	b[0].x = 100
	b[0].y = 100
	b[0].dx = 5.2
	b[0].dy = 3.2
	b[0].col = rgbcolor(0, 100, 200)
	b[1].x = 600
	b[1].y = 200
	b[1].dx = -5.2
	b[1].dy = 3.2
	b[1].col = rgbcolor(200, 100, 0)
	b[2].x = 700
	b[2].y = 500
	b[2].dx = -1.2
	b[2].dy = 3.2
	b[2].col = rgbcolor(0, 200, 0)
	screen1(50, 20, 1000, 768, 32)
	clearcolor(rgbcolor(0, 0, 100))
	while 1
		move(b)
		edges(b)
		BallCollisions(b)
		'getmouse1(@mx, @my, @mw, @mb)
		screenlock1()
		clearscreen1()
		_draw(b)
		drawstring(50, 10, " Press escape key to end", rgbcolor(255, 200, 0))
		drawstring(0, 55, "framerate", rgbcolor(0, 200, 0))
		locate1(8, 11)
		printdbl(fps, 0)
		screenunlock1()
		sleeptime = regulate(65, @fps)
		sleep1(sleeptime)
		endkey1()
	wend
	 delete [] b
     return 0
end function
main


 
Note
I have set the framerate to 65 fps.
If you set it to say 1000, you can compare flat out speeds in C++ and freebasic.
I get hardly any difference.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Using a freebasic dll in c++

Post by Boromir »

BasicCoder2 wrote:What is it you want to do with C that you aren't able to do with FreeBASIC?.
Nothing specifically but if I ever became more than a simple hobbyist programmer (which I can see coming) I would probably be forced into the C/C++ arena. So I'm just attempting to get a jump start on that.
Also I just like experimenting with different things. :)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Using a freebasic dll in c++

Post by BasicCoder2 »

dodicat wrote:If you have some spare time you could try this out. Three files...
Ok. I assume this compile with -dll involves using the command prompt window?
My only experience using FB is with compile/run from the FBIDE.
I am familiar with C and even some C++ after using it on the old MSDOS machines however even then I used an IDE to write, compile and run the programs.
Yes I will find time to give it a go and figure out how to compile a -dll.
What IDE do you use? My most recent experience has been with Code::Blocks.
.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Using a freebasic dll in c++

Post by Boromir »

BasicCoder2 wrote:
dodicat wrote:If you have some spare time you could try this out. Three files...
Ok. I assume this compile with -dll involves using the command prompt window?
My only experience using FB is with compile/run from the FBIDE.
I am familiar with C and even some C++ after using it on the old MSDOS machines however even then I used an IDE to write, compile and run the programs.
Yes I will find time to give it a go and figure out how to compile a -dll.
Fbide has the compiler command here:: FBIDE Settings|FreeBasic|Compiler Command
It should look like this

Code: Select all

"<$fbc>" "<$file>"
add -dll like this and compile one.bas. Remember to change it back or all your programs will be coming out as dlls. :)

Code: Select all

"<$fbc>" "<$file>" -dll
If you want to use the command line do this(assuming you have an environment variable for fbc)

Code: Select all

fbc one.bas -dll
For the c++ file you have to link to the freebasic dll (this assumes you have mingw setup)

Code: Select all

gcc file2.cpp -o graphics -L"C:/path  to one.dll/" -lone
It should result in graphics.exe.
What IDE do you use? My most recent experience has been with Code::Blocks.
.
CodeBlocks is a good choice. I use it too sometimes but generally "sublime text" ,an all putpose text editor, is good enough for me. I also have devc++.
On Linux I use Geany.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using a freebasic dll in c++

Post by dodicat »

I use, in fbide, for one .bas :

"<$fbc>" -lang fb -gen gcc -dll "<$file>"

(you can use -gen gas if you wish)



This produces one.dll and libone.dll.a

If you are using the dll file in the same folder as a graphics .cpp or graphics.bas, you can delete libone.dll.a from the folder. (optional)

I use the DevC++ ide.
If I go tools -- compiler options, I can write -lone in the given box (as the required command line switch).

(I am not sure how to call the dll from code in C++, like FreeBASIC, which uses #inclib "one")
I have googled for a method but nothing I tried works.

I get a couple of compiler warnings from DevC++
--- [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
I am not sure how to fix these warnings, but it compiles to .exe and runs with no problems.


Did you get the graphics to work in C++ ?
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Using a freebasic dll in c++

Post by caseih »

dodicat wrote:(I am not sure how to call the dll from code in C++, like FreeBASIC, which uses #inclib "one")
I have googled for a method but nothing I tried works.
Neither C nor C++ know anything about shared libraries or dlls. They just refer to symbols (thanks to header files) and it's the linker's job to tell the loader which DLLs to bring in and dynamically link the symbols at runtime. So you'll never find a method for doing this because it's not part of the compiler.

FBC is kind of a combination of compiler and linker, hence the "#inclib" directive. Personally I wish inclib had never been added to FB. I think specifying the library should never be a code-level thing, but rather left to the linking step. What if I want to link against a different but compatible DLL? With FB I have to edit the .bi file to make sure it's pointing at the new dll. But I can understand why FBC has inclib as it makes life easier for newbies.
Boromir
Posts: 463
Joined: Apr 30, 2015 19:28
Location: Oklahoma,U.S., Earth,Solar System
Contact:

Re: Using a freebasic dll in c++

Post by Boromir »

dodicat wrote: I get a couple of compiler warnings from DevC++
--- [Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
I am not sure how to fix these warnings, but it compiles to .exe and runs with no problems.
The warning is from your drawstring. It takes in a variable but your giving it a constant string.

Code: Select all

 drawstring(50,10," Press escape key to end",rgbcolor (255,200,0));
 drawstring(0,55,"framerate",rgbcolor(0,200,0));
Try using strdup("const string")
#include <string.h>

Code: Select all

 drawstring(50,10,strdup(" Press escape key to end"),rgbcolor (255,200,0));
 drawstring(0,55,strdup("framerate"),rgbcolor(0,200,0));
Post Reply