Howto use DLL's?

BlitzMax Forums/BlitzMax Beginners Area/Howto use DLL's?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here is the final code which I can include in all my projects which must use the relais interface card.

' Relaishandler v1.0 for Quancom USBREL8LC USB Relais interface

' Written by Mark Gerritsen

' Use :

' relais (x, x, x, x, x, x, x, x) to activate relais
' x can be either 1 or 0 and each x handles 1 relais


' Load Quancoms Qlib library 
dll = LoadlibraryA ("qlib32")

If dll=Null
 RuntimeError "Unable to load library"
 End
EndIf

Global QAPIExtOpenCard:Int (cardid:Int, devnum:Int) "win32"
Global QAPIExtCloseCard (cardhandle:Int) "win32"
Global QAPIExtWriteDO32 (cardhandle:Int, channel:Int, value:Int, mode:Int) "win32"
Global handle:Int

QAPIExtNumOfCards = GetProcAddress(dll, "QAPIExtNumOfCards")
QAPIExtOpenCard = GetProcAddress(dll, "QAPIExtOpenCard")
QAPIExtWriteDO32 = GetProcAddress(dll, "QAPIExtWriteDO32")
QAPIExtCloseCard = GetProcAddress(dll, "QAPIExtCloseCard")

Local cardnumber:Int = 0

While handle = 0
If cardnumber > 8
RuntimeError "Unable find card"
  End
EndIf
handle = QAPIExtOpenCard(67,cardnumber)
cardnumber = cardnumber + 1
Wend

' Reset Relais interface
relais(0,0,0,0,0,0,0,0)

Function relais(out1:Int,out2:Int,out3:Int,out4:Int,out5:Int,out6:Int,out7:Int,out8:Int)
Local value = 0
If out1 = 1 Then value = value + 1
If out2 = 1 Then value = value + 2
If out3 = 1 Then value = value + 4
If out4 = 1 Then value = value + 8
If out5 = 1 Then value = value + 16
If out6 = 1 Then value = value + 32
If out7 = 1 Then value = value + 64
If out8 = 1 Then value = value + 128
Print value
QAPIExtWriteDO32(handle,0,value,0)
QAPIExtCloseCard(handle)
End Function


Now I can use an easy function to activate all relais using relais(1,1,1,1,1,1,1,1) or relais(0,0,0,0,0,0,0,0) to disable them all, or any other combination.

Now I can continue with my arcade project :-)