Passing a type to a DLL API

BlitzMax Forums/BlitzMax Programming/Passing a type to a DLL API

This is how I have done it.

Type MIDIOUTCAPS 
	Field wMid:Short
	Field wPid:Short
	Field vDriverVersion:Int' MMVERSION 
	Field szPname_0,szPname_1,szPname_2,szPname_3 
	Field szPname_4,szPname_5,szPname_6,szPname_7
	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:Byte Ptr, uSize:Int) 
End Extern

Local MaxOutDev =  midiOutGetNumDevs()
Print "MaxOutDev = "+MaxOutDev 
Print

Local InfoOut:MidiOutCaps = New MidiOutCaps 
Local MidiOutCapsPtr:Byte Ptr = Varptr(InfoOut.wMid)
' Note NOT pointing to BlitMax type but to FIRST field in type.
 
For count = -1 To MaxOutDev
  Print "DEVICE : "+count
  midiOutGetDevCapsA(count,MidiOutCapsPtr ,  SizeOf(MIDIOUTCAPS ))
  If (InfoOut<> Null) Then

    Print "  wMid "+Int(InfoOut.wMid)

    Print "  wPid "+Int(InfoOut.wPid)
    Print "  vDriverVersion "+InfoOut.vDriverVersion

    Print "  szPname" + String.FromCString(Varptr(InfoOut.szPname_0))
    Print "  wTechnology " + InfoOut.wTechnology
    Print "  wVoices " + InfoOut.wVoices
    Print "  wNotes "+ InfoOut.wNotes
    Print "  wChannelMask " + InfoOut.wChannelMask
    Print "  dwSupport " + InfoOut.dwSupport
  EndIf
Next


This is the trick;

Local InfoOut:MidiOutCaps = New MidiOutCaps
Local MidiOutCapsPtr:Byte Ptr = Varptr(InfoOut.wMid)
Using the 1st field not the Type pointer.

And for looking at Cstrings in memory use String.FromCString(Varptr( StringPos))

Now we can use structures from external libs!!!!