Howto use DLL's?
BlitzMax Forums/BlitzMax Beginners Area/Howto use DLL's?
| ||
Is there any good documentation available on how to use DLL's in Blitzmax where everything is explained step by step? I want to use the Qlib32 library from www.quancom.com to send data to my USB relais interface. I know which functions I need to use from the DLL and the values I need to send to them to control it, but I'm not sure where to start in Blitzmax so that I am able to send/receive data from this DLL. The functions of this library I need are : QAPIExtOpenCard(cardid, devnum) <= cardhandle QAPIExtCloseCard(cardhandle) QAPIExtWriteDo32(cardhandle, channel, value, mode) The reason I want to use this is because of an Arcade project, I want to control the Leds and coin mechanism from within the games itself which I want to write for it. If someone could help me a bit or send me in the right direction I would be greatfull. |
| ||
If you don't have a lib file you can still use the DLL by the LoadLibrary API |
| ||
There is a Qlib32.LIB available also. And there are also loads of examples available for Visual basic and Delphi. But in Blitzmax I don't know how the code should look like. The examples which I could find on this forum where a bit confusing for me... |
| ||
I'm not sure if this is the correct way to start, but this is what I made so far : dll = LoadlibraryA ("qlib32") Global QAPIExtOpenCard:Long(cardid:Long, devnum:Long) = GetProcAddress(dll, "QAPIExtOpenCard") Global QAPIExtWriteDo32:Long(cardhandle:Long, channel:Long, value:Long, mode:Long) = GetProcAddress(dll, "QAPIExtWriteDo32Card") Global QAPIExtCloseCard:Long(cardhandle:Long) = GetProcAddress(dll, "QAPIExtCloseCard") If this is correct I can go one step further... |
| ||
Woohoo!, found it.... I needed Int instead of Long. I tried the following code and the dll gave me back the results. Global QAPIExtOpenCard (cardid:Int, devnum:Int) "win32" Global QAPIExtCloseCard (cardhandle:Int) "win32" Global QAPIExtWriteDO32 (cardhandle:Int, channel:Int, value:Int, mode:Int) "win32" Global QAPIExtNumOfCards () dll = LoadlibraryA ("qlib32") If dll=Null Print "Dammit" End EndIf QAPIExtNumOfCards = GetProcAddress(dll, "QAPIExtNumOfCards") QAPIExtOpenCard = GetProcAddress(dll, "QAPIExtOpenCard") QAPIExtWriteDO32 = GetProcAddress(dll, "QAPIExtWriteDO32") QAPIExtCloseCard = GetProcAddress(dll, "QAPIExtCloseCard") Local handle:Int = QAPIExtOpenCard(67,1) Print handle Print QAPIExtNumOfCards() I only need to test it with my relais card connected when I get home. But I'm glad I know how to work with dll's now... took me some days |
| ||
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 :-) |
| ||
Hi Mark, I was trying the same as you but couldn't get it to work. You seem to have the ID 67 in this line: handle = QAPIExtOpenCard(67,cardnumber) I do get it to work with such a device, but with numer 64... how can we let the program choose the right ID by itself? |