DLL help

Previous topic - Next topic

Maxheadroom

Ok I omit defeat with the inline command the problem is I just can’t work how it works, I even have the full description file from the supplier. If I send you the dll and the document, can you show me how to get one or two of the commands working, I am sure if you show me one or two I could work out the rest out!

Thanks, Max…

EDIT:
Problem is solved, COM port communication is working. See best answer here:
http://www.glbasic.com/forum/viewtopic.php?pid=2499#p2499

Hemlos

Bing ChatGpt is pretty smart :O

Maxheadroom

Ok that’s great!

Can we start with the simple stuff, I have loads more questions.

1, a Dll file will give GLBAISC extra commands? True/false
2, can I use the commands as if they were part of the glbasic
3, how do variables connect with glabsic variables?

 
thanks, Max

Kitty Hello

I got your mail. Oh boy. That's a lot of work. I tell you the basics, but I can't do it all for you.

If you read Visual Basic:

Code (glbasic) Select
Private Declare Function XY Lib "xyz.dll" (a As Long) As DoubleYou write:
Code (glbasic) Select
INLINE
extern "C" double (__stdcall* XY)(long a)=0;
DLLCALL("xyz.dll", "XY", (void**) &XY);
ENDINLINE
Now the details:
INLINE - that starts inline C++ programming

Then comes the function declaration - tell the compiler, there is a function called XY that takes a 'long' argument and returns a double.

extern "C" - the call is an extern "C" declaration - for VB callable DLLs it's always this:
extern "C" return_value(__stdcall* FunctionName) (arguments);

Code (glbasic) Select
double - that's the return value. Use these:
int - 32 bit integer - the same as 'long'
short - 16 bit integer (that's Integer in VB)
char - 8 bit integer
double - 64 bit floating point
float  - 32 bit floating point
char*  - a String
void*  - any pointer - you can use 'int' as well...
(__stdcall* - the calling convention. VB can only handle stdcall (double underscore at the beginning)

XY ) - The function name. That's the name you give the function internally (when you call it) It can differ from the real name.

(long a) - here comes the parameter list, separated by commas. You can leave the variable names 'a' if you want to. Only the types are of interest.

=0 - you say the function pointer equals '0'. This way can test if the function got loaded later.


DLLCALL( dll_name, function_name_witin_the_dll, (void**) &function_name_of_declaration);


If you want to call the function, you write:
Code (glbasic) Select
LOCAL retval, inval
INLINE
retval = XY(inval);
ENDINLINE
Read the reference for INLINE as well. It tells you how to connect/convert GLBasic data into C++ data.

Maxheadroom

your the man!, i will try it tonight very slowly. (Sure to have more questions later)

thank you very much for the pointers.

Maxheadroom

first i tryed this (not even working)?

Code (glbasic) Select
// --------------------------------- //
// Project:
// Start: Monday, October 23, 2006
// IDE Version: 3.283

LET lt=1
LET chip=1

startup
setltp
setoutput

END


INLINE
DLLCALL("K8D.dll", "start_8000", (void**) &start_8000);
DLLCALL("K8D.dll", "SelectI2CprinterPort", (void**) &SelectI2CprinterPort);
DLLCALL("K8D.dll", "ConfigIOchipAsOutput", (void**) &ConfigIOchipAsOutput);
extern "C" double (__stdcall* start_8000);
extern "C" double (__stdcall* SelectI2CprinterPort) (long lt);
extern "C" double (__stdcall* ConfigIOchipAsOutput) (long chip);
ENDINLINE


FUNCTION startup:
INLINE
start8000
ENDINLINE
ENDFUNCTION

FUNCTION setltp: it
INLINE
SelectI2CprinterPort (it)
ENDINLINE
ENDFUNCTION

FUNCTION setoutput: chip
INLINE
ConfigIOchipAsOutput (chip)
ENDINLINE
ENDFUNCTION
then i tryed this ?
Code (glbasic) Select
// --------------------------------- //
// Project:
// Start: Monday, October 23, 2006
// IDE Version: 3.283

LET lt=1
LET chip=1

// load the start up io
INLINE
extern "C" double (__stdcall* start8000);
DLLCALL("K8D.dll", "start_8000", (void**) &start8000);
ENDINLINE

// load lpt1
INLINE
extern "C" double (__stdcall* setltp1) (long lt);
DLLCALL("K8D.dll", "SelectI2CprinterPort", (void**) &SelectI2CprinterPort);
ENDINLINE

// load lpt1
INLINE
extern "C" double (__stdcall* setltp1) (long chip);
DLLCALL("K8D.dll", "ConfigIOchipAsOutput", (void**) &ConfigIOchipAsOutput);
ENDINLINE

PRINT 100,100,lt
SHOWSCREEN
MOUSEWAIT
and that a some errors

Code (glbasic) Select
compiling:
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:10: error: `LET' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:10: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:10: error: expected `;' before "lt"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:11: error: expected `;' before "chip"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:15: error: expected primary-expression before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:15: error: expected `;' before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:16: error: `start8000' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:22: error: expected primary-expression before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:22: error: expected `;' before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:23: error: `SelectI2CprinterPort' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:29: error: expected primary-expression before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:29: error: expected `;' before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:30: error: `ConfigIOchipAsOutput' undeclared (first use this function)

linking:
success
_______________________________________
*** Finished ***
Time: 1.4 sec
Build: 1 succeeded, 0 failed

Kitty Hello

Quote from: Maxheadroomfirst i tried this (not even working)?

Code (glbasic) Select
// --------------------------------- //
// Project:
// Start: Monday, October 23, 2006
// IDE Version: 3.283

// LET is dead. Please leave it.
lt=1
chip=1

// a function must be called with ( )
startup()
setltp(lt)
setoutput(chip)

END

// You must "end" the main game function
// this is done by forcing another function to
// begin and end
FUNCTION dummy:
ENDFUNCTION


INLINE
// here the order got messed up.
// first declaration and definition
// then linking to it

// also, don't forget the "=0", so you can check if
// the function has been loaded

extern "C" double (__stdcall* start_8000) = 0;
extern "C" double (__stdcall* SelectI2CprinterPort) (long lt) = 0;
extern "C" double (__stdcall* ConfigIOchipAsOutput) (long chip) = 0;

DLLCALL("K8D.dll", "start_8000", (void**) &start_8000);
DLLCALL("K8D.dll", "SelectI2CprinterPort", (void**) &SelectI2CprinterPort);
DLLCALL("K8D.dll", "ConfigIOchipAsOutput", (void**) &ConfigIOchipAsOutput);

ENDINLINE


FUNCTION startup:
INLINE
// in C++ always call functions with ( )
// and end a command with ';'

// also, check if the function could be loaded first:

if (start8000) // function pointer is good
{
   start8000();
}
else
{
   PRINT("Can't load function", 100, 100);
   SHOWSCREEN();
   MOUSEWAIT();
   END();
}
ENDINLINE
ENDFUNCTION

FUNCTION setltp: it
INLINE
SelectI2CprinterPort (it); // semicolon
ENDINLINE
ENDFUNCTION

FUNCTION setoutput: chip
INLINE
ConfigIOchipAsOutput (chip); // semicolon
ENDINLINE
ENDFUNCTION

Maxheadroom

Thanks that’s starting to make more sense, I will try it tonight, however should the call be  start_8000(); ?

thanks max...

Kitty Hello

Right. Typo from me. Just wanted to see if you read carefully ;)

Maxheadroom

so close but so far.

Code (glbasic) Select
// --------------------------------- //
// Project:
// Start: Monday, October 23, 2006
// IDE Version: 3.283

// LET is dead. Please leave it.
lt=1
chip=1
info=10

// a function must be called with ( )


startup()

setltp(lt)

setoutput(chip)

output(chip, info)

END

INLINE
extern "C" double (__stdcall* start_8000) = 0;
extern "C" double (__stdcall* SelectI2CprinterPort) (long lt) = 0;
extern "C" double (__stdcall* ConfigIOchipAsOutput) (long chip) = 0;
extern "C" double (__stdcall* IOoutput) (long chip, long info) = 0;
DLLCALL("K8D.dll", "start_8000", (void**) &start_8000);
DLLCALL("K8D.dll", "SelectI2CprinterPort", (void**) &SelectI2CprinterPort);
DLLCALL("K8D.dll", "ConfigIOchipAsOutput", (void**) &ConfigIOchipAsOutput);
DLLCALL("K8D.dll", "IOoutput", (void**) &IOoutput);
ENDINLINE

// You must "end" the main game function
// this is done by forcing another function to
// begin and end
FUNCTION dummy:
ENDFUNCTION



FUNCTION startup:
INLINE
// in C++ always call functions with ( )
// and end a command with ';'

// also, check if the function could be loaded first:

IF (start_8000) // function pointer is good
{
   start_8000();
}
ELSE
{
   PRINT("Can't load function", 100, 100);
   SHOWSCREEN();
   MOUSEWAIT();
   END();
}
ENDINLINE
ENDFUNCTION

FUNCTION setltp: it
INLINE
SelectI2CprinterPort (it); // semicolon
ENDINLINE
ENDFUNCTION

FUNCTION setoutput: chip
INLINE
ConfigIOchipAsOutput (chip); // semicolon
ENDINLINE
ENDFUNCTION

FUNCTION output: chip, info
INLINE
IOoutput (chip,info); // semicolon
ENDINLINE
ENDFUNCTION
out put of the complier
Code (glbasic) Select
_______________________________________
*** Configuration: WIN32 ***
precompiling...

GPC - GLBasic Precompiler V.2006.279 - 3D, NET
compiling...
k8000.gbas (1 KB)
Wordcount:10 commands

compiling:
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `int __GLBASIC__::__MainGameSub_()':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:22: error: expected primary-expression before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:22: error: expected `;' before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:23: error: expected primary-expression before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:23: error: expected `;' before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:24: error: expected primary-expression before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:24: error: expected `;' before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:25: error: expected primary-expression before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:25: error: expected `;' before "extern"
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:26: error: `start_8000' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:26: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:27: error: `SelectI2CprinterPort' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:28: error: `ConfigIOchipAsOutput' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:29: error: `IOoutput' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::startup()':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:50: error: `start_8000' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:50: error: `IF' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:51: error: expected `;' before '{' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:55: error: `ELSE' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:55: error: expected `;' before '{' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::setltp(DGInt)':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:70: error: `SelectI2CprinterPort' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::setoutput(DGInt)':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:80: error: `ConfigIOchipAsOutput' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::output(DGInt, DGInt)':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:90: error: `IOoutput' undeclared (first use this function)

linking:
success
_______________________________________
*** Finished ***
Time: 1.3 sec
Build: 1 succeeded, 0 failed

Kitty Hello

You forgot a:
FUNCTION End_My_Main:
ENDFUNCTION

after the "END"

Maxheadroom

gernot
is this bit ok it needs two verables

extern "C" double (__stdcall* IOoutput) (long chip, long info) = 0;

Kitty Hello

It says: "Private Declare Sub" in VB. Thus, this is a void function:

extern "C" void (__stdcall* IOoutput)(long, long)=0;

You're really close now, I guess.

Maxheadroom

it's all gone wrong, so i have striped it. however this will not build. i must be missing somthing: :D
Code (glbasic) Select
// --------------------------------- //
// Project:
// Start: Wednesday, November 01, 2006
// IDE Version: 3.283

up()

END
FUNCTION End_My_Main:
ENDFUNCTION


FUNCTION up:
INLINE
start_8000();
ENDINLINE
ENDFUNCTION



INLINE
extern "C" double (__stdcall* start_8000) = 0;
DLLCALL("K8D.dll", "start_8000", (void**) & start_8000);
ENDINLINE
the error
Code (glbasic) Select
*** Configuration: WIN32 ***
precompiling...

GPC - GLBasic Precompiler V.2006.279 - 3D, NET
compiling...
one.gbas (365 B )
Wordcount:3 commands

compiling:
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: In function `DGInt __GLBASIC__::up()':
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:24: error: `start_8000' undeclared (first use this function)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:24: error: (Each undeclared identifier is reported only once for each function it appears in.)
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp: At global scope:
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:31: error: `double*__GLBASIC__::start_8000' used prior to declaration
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:32: error: expected constructor, destructor, or type conversion before '(' token
C:\Program Files\GLBasic\Compiler\platform\gpc_temp0.cpp:32: error: expected `,' or `;' before '(' token

linking:
gpc_temp0.o:gpc_temp0.cpp:(.text+0x46): undefined reference to `__GLBASIC__::t'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x88): undefined reference to `__GLBASIC__::t'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xae): undefined reference to `__GLBASIC__::t'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xc8): undefined reference to `__GLBASIC__::t'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xd1): undefined reference to `__GLBASIC__::lt'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xde): undefined reference to `__GLBASIC__::chip'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xe4): undefined reference to `__GLBASIC__::info'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xea): undefined reference to `__GLBASIC__::info'
gpc_temp0.o:gpc_temp0.cpp:(.text+0xf0): undefined reference to `__GLBASIC__::t'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x128): undefined reference to `__GLBASIC__::t'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x158): undefined reference to `__GLBASIC__::t'
gpc_temp0.o:gpc_temp0.cpp:(.text+0x164): undefined reference to `__GLBASIC__::t'
*** FATAL ERROR - Please post this output in the forum
_______________________________________
*** Finished ***
Time: 0.8 sec
Build: 0 succeeded, 1 failed

Kitty Hello

Code (glbasic) Select
up()

END

FUNCTION End_My_Main:
ENDFUNCTION

// Must declare function _before_ you use them!!
INLINE
extern "C" double (__stdcall* start_8000) = 0;
DLLCALL("K8D.dll", "start_8000", (void**) & start_8000);
ENDINLINE



FUNCTION up:
INLINE
start_8000();
ENDINLINE
ENDFUNCTION