A dll function returns a pointer to a array of structures.
Code,
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)
'???
Exception
DisplayException(CurrentMethodName)
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 ?
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
dicMidiDevices.RemoveAll
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)
Next