DrDAQ control with Xojo

Hi All
Hope someone with windows VB declares experience can help with this.
DrDAQ is an educational DAQ card with a number of inputs/outputs.
It comes with a DLL (USBDrDAQ.dll) for use with VB and VBA and Excel.
Unfortunately, it only comes with an Excel VBA example which made it more difficult for me (beginner) to convert to Xojo.
going through as many resources I could find, I managed to read and control most of the functions of the unit with the DLL provided and most of the declares converted, which was very pleasing knowing what one can accomplish with Xojo.
With this projects I gain considerable knowledge on how to apply declares from VB to Xojo. I had no problems with integers but when it came to strings I got a bit lost. I download “… Implement Declares with Xojo on Windows” By Eugene Dakin but found that my understanding on the strings need more work. I am hoping with this real life example it will boost my understanding.

After all that, here is the declare I have problem with – the VBA Declare is:

Declare Function UsbDrDaqGetUnitInfo Lib “USBDrDAQ.dll” (ByVal handle As Integer, ByVal S As String, ByVal stringLength As Integer, ByRef requiredSize As Integer, ByVal info As Long) As Long

The long is changed to Int32 which worked for all other declares but this declare had ByVal S As String which Xojo did not except and said t use CString etc.

The following is in the VBA

Dim handle As Integer
Dim Row As Integer
Dim requiredSize As Integer
Dim S As String * 255 (I could not find how to convert this to Xojo)

’ Get the unit information
Cells(10, “L”).value = “Unit opened”
SLegnth = UsbDrDaqGetUnitInfo(handle, S, 255, requiredSize, 3)
Cells(11, “L”).value = S
SLegnth = UsbDrDaqGetUnitInfo(handle, S, 255, requiredSize, 4)
Cells(12, “L”).value = “Serial number:”
Cells(12, “M”).value = S
SLegnth = UsbDrDaqGetUnitInfo(handle, S, 255, requiredSize, 0)
Cells(13, “L”).value = “Driver version:”
Cells(13, “M”).value = S

Note: the SLegnth is declared anywhere but works in the Excel VBA, is it a VB specific function?
Hoping someone can help get these 3 calls to 3 textfields.

Excel does not force you to declare variables. By default, all variables in Excel will have the Variant type, and can be assigned a number or text. (see http://www.excelfunctions.net/VBA-Variables-And-Constants.html)
SLegnth is probably not declared in the Excel example, and that won’t cause an error in Excel.
In Xojo you need to declare though.
You probably need to declare this one as an integer.
So Add a dim SLegnth As Integer and see if that helps.

Hi Dirk,
Thanks for trying to help. I almost lost hope.
I tried your suggestion. Only getting “0” for all 3 calls. with Xojo.
In excel S outputs the following info in each call of SLegnth


I don’t understand how S is being formed in each case from
SLegnth = UsbDrDaqGetUnitInfo(handle, S, 255, requiredSize, 3)
SLegnth = UsbDrDaqGetUnitInfo(handle, S, 255, requiredSize, 4)
SLegnth = UsbDrDaqGetUnitInfo(handle, S, 255, requiredSize, 0)

It may have to do with the string type in the declare

Apart from this, I got the unit’s main functions working so it’s not a problem but a challenge to learn VB declares conversions to Xojo.
Help is much appreciated.

When SLegnth is related to a Len() or Length() function, maybe the original var is spelled SLength?

From the documentation, it looks like S should be Ptr not ByVal as that is where the data comes back:

Declare Function UsbDrDaqGetUnitInfo Lib "USBDrDAQ.dll" (handle As Integer,  S As Ptr, stringLength As Integer, ByRef requiredSize As Integer, info As Int64) As Int64

Define S as a MemoryBlock:

Dim S As MemoryBlock(255)

Call your .dll function:

SLegnth = UsbDrDaqGetUnitInfo(handle, S, 255, requiredSize, 3)

SLegnth will have the status (error) number for the function call.
The result should be in:


Thanks a lot John for the solution, It also helps me to have a better understanding of memory blocks.
You also gave me a chance to troubleshoot :
Dim S As MemoryBlock(255) gave a syntax error it should be Dim S As New MemoryBlock(255)
I got exactly the right info for all the .dll function calls.
Enjoying Xojo more and more.

You’re welcome. I’ve found a ton of information and help on this forum myself, I’m glad to give back once in awhile.

That was mostly from memory, as I haven’t had a project that needed declares for awhile.

Dim ... as New ... still gets me every now and then.

Thanks to the forum help I put a small example for accessing the DrDAQ device if anyone is interested.
Thanks again for the forum help. Now I am having fun playing with this device.