I have found a way to load dll's into c++ via code (no need to alter anything in the dev c++ ide settings)
From scratch
Put this .bas file and the c++ file in the same folder.
graphics.bas
compile with -dll to get graphics.dll
Code: Select all
'graphics.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 integer,y1 as integer,c as uinteger) EXPORT
pset (x1,y1),c
end sub
sub clearscreen1() export
cls
end sub
sub endkey1(n as integer) export
if inkey=chr(n) then end
end sub
sub screenlock1(dummy as integer) export
screenlock
end sub
sub screenunlock1(dummy as integer) 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
Code: Select all
#include <windows.h>
#include <math.h>
#include<new>
typedef double ( * thernd)(int);
typedef void (* thescreen)(int,int,int,int,int);
typedef void (* thedrawstring)(int x,int y,char* text,unsigned int c);
typedef void ( * theprintdbl)(double n,int flag);
typedef void ( * thecirclefill1)(int x1,int y1,int rad,unsigned int c);
typedef void ( * thecircle1)(int x1,int y1,int rad,unsigned int c);
typedef void ( * theline1)(int x1,int y1,int x2,int y2,unsigned int c);
typedef unsigned int ( * thergbcolor)(int r,int g,int b);
typedef void ( * thescreenlock1)();
typedef void ( * thescreenunlock1)();
typedef void ( * thesleep1)(int n);
typedef void ( * theclearscreen1)();
typedef void ( * theendkey1)(int);
typedef void ( * thelocate1)(int x,int y);
typedef int ( * theframecounter)();
typedef void ( * thegetmouse1)(int *mx,int *my,int *mw,int *mb);
typedef int ( * theregulate)(int myfps,int *fps);
typedef void ( * theclearcolor)(unsigned int c);
typedef void ( * thepset1)(int,int,unsigned int);
typedef void ( * thewaitkey)();
HMODULE Module = LoadLibrary("graphics.dll");
thernd rnd = (thernd) GetProcAddress(Module, "_Z7randomsi");
thescreen screen = (thescreen) GetProcAddress(Module, "_Z7screen1iiiii");
thedrawstring drawstring = (thedrawstring) GetProcAddress(Module, "_Z10drawstringiiPcj");
thergbcolor rgb= (thergbcolor) GetProcAddress(Module, "_Z8rgbcoloriii");
theprintdbl print= (theprintdbl) GetProcAddress(Module, "_Z8printdbldi");
thecirclefill1 circlefill= (thecirclefill1) GetProcAddress(Module, "_Z11circlefill1iiij");
thecircle1 circle = (thecircle1) GetProcAddress(Module, "_Z7circle1iiij");
theline1 line =(theline1) GetProcAddress(Module, "_Z5line1iiiij");
thescreenlock1 screenlock=(thescreenlock1) GetProcAddress(Module, "_Z11screenlock1i");
thescreenunlock1 screenunlock = ( thescreenunlock1) GetProcAddress(Module, "_Z13screenunlock1i");
thesleep1 sleep = (thesleep1) GetProcAddress(Module, "_Z6sleep1i");
theclearscreen1 clearscreen = (theclearscreen1)GetProcAddress(Module, "_Z12clearscreen1v");
theendkey1 endkey = (theendkey1) GetProcAddress(Module, "_Z7endkey1i");
thelocate1 locate = (thelocate1) GetProcAddress(Module, "_Z7locate1ii");
theframecounter framerate = (theframecounter) GetProcAddress(Module, "_Z12framecounterv");
thegetmouse1 getmouse = ( thegetmouse1) GetProcAddress(Module, "_Z9getmouse1PiS_S_S_");
theregulate regulate = (theregulate) GetProcAddress(Module, "_Z8regulateiPi");
theclearcolor clearcolor = (theclearcolor) GetProcAddress(Module, "_Z10clearcolorj");
thepset1 putpixel = (thepset1) GetProcAddress(Module, "_Z5pset1iij");
thewaitkey wait = (thewaitkey) GetProcAddress(Module, "_Z7waitkeyv");
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++)
{
circlefill(b[n]->x,b[n]->y,50,b[n]->col);
circle(b[n]->x,b[n]->y,50,rgb(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=rgb(0,100,200);
b[1]->x=600;
b[1]->y=200;
b[1]->dx=-5.2;
b[1]->dy=3.2;
b[1]->col=rgb(200,100,0);
b[2]->x=700;
b[2]->y=500;
b[2]->dx=-1.2;
b[2]->dy=3.2;
b[2]->col=rgb(0,200,0);
screen(50,20,1000,768,32);
clearcolor(rgb(0,0,100));
while (1)
{
move(&b[0]);
edges(&b[0]);
BallCollisions(&b[0]);
screenlock();
clearscreen();
draw(&b[0]);
drawstring(50,10," Press escape key to end",rgb (255,200,0));
drawstring(0,55,"framerate",rgb(0,200,0));
locate (8,11);
print(fps,0);
screenunlock();
sleeptime=regulate(65,&fps);
sleep(sleeptime);
endkey(27);
}
//delete [] b;
}