User Defined types By Ref ?

BlitzMax Forums/BlitzMax Beginners Area/User Defined types By Ref ?

Ziltch(Posted 2004) [#1]
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.


Bot Builder(Posted 2004) [#2]
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.


marksibly(Posted 2004) [#3]
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 )


Ziltch(Posted 2004) [#4]
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!!


semar(Posted 2005) [#5]
A question:

For count = -1 To MaxOutDev



Why does count start from -1 ? Shouldn't start from 0 ?

Sergio.


Ziltch(Posted 2005) [#6]
No. Out devices do start at -1 for some reason.

Working code to look at all Midi Output devices.




semar(Posted 2005) [#7]
@Ziltch,
thank you - really appreciated.

Sergio.