Page 1 of 1

PLEASE HELP ME :)

Posted: Mon Jan 04, 2010 1:57 am
by Chopepo
Hi:

I know how is to create a DLL to call coolbasic as this to function.

Can I create a DLL taken to control the parallel port for example?
How are the memblocks?

and finally ...

How do I use the INCLUDE command?
I tried to use the include but when I compile I get an error.

Your help will be very useful to me.
Thank you very much in advance.

Bye.

Re: PLEASE HELP ME :)

Posted: Mon Jan 04, 2010 4:02 am
by valscion
Chopepo wrote:How do I use the INCLUDE command?
I tried to use the include but when I compile I get an error.
As for the other questions, I can't help you. But I'll give a try for this one; include basically includes, adds the insides of another textfile (like a .cb file) to your current program. This way you can easily chop your code to smaller bits and therefore help reading and creating it.

For instance, you could have a sourcecode in functions.CB file looking like this:

Code: Select all

Function MyFunction( txt$ )
  MakeError "This is MY function!"+Chr(10)+Chr(13)+txt$
EndFunction
and then you could have your actual sourcecode and mainloop in game.CB file looking like this:

Code: Select all

Include "functions.CB"

Repeat
  If KeyHit(cbKeyReturn) Then MyFunction( "Return pressed!" )
  Text 0, 0, "Press RETURN"
  DrawScreen
Forever
Can you see the first line? It adds the functions.CB file to the code that goes to CoolBasic Compiler which creates the final EXE file. So basically it's the same as if you would write it all to one file, looking like this:

Code: Select all

Function MyFunction( txt$ )
  MakeError "This is MY function!"+Chr(10)+Chr(13)+txt$
EndFunction

Repeat
  If KeyHit(cbKeyReturn) Then MyFunction( "Return pressed!" )
  Text 0, 0, "Press RETURN"
  DrawScreen
Forever
After you get hundreds of lines of code, chopping up the code to smaller pieces to different files will help you a lot. And that's what the INCLUDE command is for :)

I hope this clears things up for you ;)

Later!

Re: PLEASE HELP ME :)

Posted: Mon Jan 04, 2010 8:58 am
by Zero
To control serial port (and the like) via CoolBasic, you'll first need to create a DLL file in C/C++ (functions must be declared with "extern C" to prevent C++ name mangling). Inside your DLL you write the necessary program logic to control the serial port; the DLL only exposes an interface for CoolBasic. You mentioned that you're already familiar with calling external code from CoolBasic, so I assume the real problem for you is to create the actual serial port controller. In this I cannot help you, but you use memblocks in exactly the same way you would otherwise pass data back to a CoolBasic program. It could be something like a poller function you'd call regularly to receive serial port state (and optionally the other way around i.e. pass data over through the serial port).

Re: PLEASE HELP ME :)

Posted: Mon Jan 04, 2010 7:04 pm
by chopepo - :)
Thank you very much, very clear to me.

:D