Dll returns array of structures

XOJO 2019r3.2 / Windows Desktop

A dll function returns a pointer to a array of structures.

Var rtn As Integer
Var no_devices As Integer
Var hpDevices As HP_DEVICE

Declare Function _
HP_GetMIDIDevices _
Lib “HP_midifile.dll” _
Alias “?HP_GetMIDIDevices@@YAIPAPAUHP_device@@PAH@Z” _
(ByRef hpDevices As HP_DEVICE, ByRef no_devices As Integer) _
As Integer

rtn = HP_GetMidiDevices(hpDevices, no_devices)
If rtn > HP_ERR_NONE Then DisplayHP_Error(“HP_GetMidiDevices”, currentMethodName, rtn)



HP_DEVICE is the structure defined as follows,
device_id As Integer / Offset = 0 / size = 4
device_name As CString*32 / Offset = 4 / size = 32

How can I get the device_id’s and the device-name’s from this dll into XOJO ?


In C an array return is a Ptr to the first element
So define RTN that way

From there you should be able to index from the Ptr with a structure like I show in

I wrote an open source binding for this DLL. Here’s the relevant section:


Thanks, both answer were a great help to solve my problem.

My code looks as follows now (midi device items are placed in a dictioary),

Var devList As Ptr Var devCount As UInt32 Var rtn As Integer Var i As Integer Var dev As HP_DEVICE Var key As Integer Var name As String

dicMidiDevices = New Dictionary

rtn = HP_GetMidiDevices(devList, devCount)
If rtn > HP_ERR_NONE Then DisplayHP_Error(“HP_GetMidiDevices”, currentMethodName, rtn)

Var item As Ptr = devList

For i = 0 To devCount - 1
dev = item.HP_DEVICE
key = dev.device_id
name = dev.device_name
dicMidiDevices.Value(key) = name
item = Ptr(Integer(item) + HP_DEVICE.Size)