User Defined types By Ref ?
BlitzMax Forums/BlitzMax Beginners Area/User Defined types By Ref ?
| ||
| I am trying to get info returned by a windows API function. Is it possible to use VAR with user defined types? With the code below, some garbarge info is returned then it crashes.
Type MIDIOUTCAPS
Field wMid:Short
Field wPid:Short
Field vDriverVersion:Int' MMVERSION
Field szPname:Byte[32] 'String[MAXPNAMELEN]
Field wTechnology:Short
Field wVoices:Short
Field wNotes:Short
Field wChannelMask:Short
Field dwSupport:Int
EndType
Extern "Os"
Function midiOutGetNumDevs()
Function midiOutGetDevCapsA( uDeviceID:Int, lpCaps:MIDIOUTCAPS Var, uSize:Int) ' Var = By Ref
End Extern
Local MaxOutDev = midiOutGetNumDevs()
Print "MaxOutDev = "+MaxOutDev
Local InfoOut:MidiOutCaps
For count = -1 To MaxOutDev
Print "DEVICE : "+count
midiOutGetDevCapsA(count,InfoOut:MidiOutCaps, 52)
If (InfoOut<> Null) Then
Print "wMid "+Int(InfoOut.wMid)
Print "wPid "+Int(InfoOut.wPid)
Print "vDriverVersion "+InfoOut.vDriverVersion
'Print "szPname"
Print "wTechnology " + InfoOut.wTechnology
Print "wVoices " + InfoOut.wVoices
Print "wNotes "+ InfoOut.wNotes
Print "wChannelMask " + InfoOut.wChannelMask
Print "dwSupport " + InfoOut.dwSupport
EndIf
Next
Any help would be most welcome. |
| ||
| You can try using Ptr rather than Var and then doing a Varptr on the params. I had a rather big structure with arrays etc, didnt work for me to get the structure. In your case it looks like you'll have to write a C wrapper (compiled into a module). In mine, you could grab a pointer to the structure in the dll's memory and then read the structure with pointers. |
| ||
| Hi, The szPname field will not work, as it's a Blitz array, not a static 'C' array. Currently, the only way around this is the extremely elegant... Field szPname_0,szPname_1,szPname_2,szPname_3 Field szPname_4,szPname_5,szPname_6,szPname_7 ...which will pad the 'struct' with a 32 byte 'char array'. Use Varptr szPname_0 to get the address of the 'array', eg: Print String.FromCString( Varptr infoOut.szPname_0 ) |
| ||
| Thanks Bot Builder and Mark for the very usefull Info. Mark I had wondered how to get a fixed length char string. If I use pointers how do I get the info back into my user type? And Thankyou for a great Christmas!! |
| ||
| A question: For count = -1 To MaxOutDev Why does count start from -1 ? Shouldn't start from 0 ? Sergio. |
| ||
| No. Out devices do start at -1 for some reason. Working code to look at all Midi Output devices. |
| ||
| @Ziltch, thank you - really appreciated. Sergio. |