[LEGAL]
ctSSLayer

[API]
GetProcAddress

[INCLUDE]
LoadLibrary
CallFunction_Fast
CallFunction_Indirect
LocalAllocFromString

[DEFINE]
Private Const LayerVersionID As Long = &H10001010
Private hModul As Long
Private ctSSLayer_CanUseItemInt As Long
Private ctSSLayer_LoadSongInt As Long
Private ctSSLayer_LoadSongPlayInt As Long
#If ctSSLayer_LoadSongAbort Then
  Private ctSSLayer_LoadSongAbortInt As Long
  #End If
#If ctSSLayer_LoadSongFinished Then
  Private ctSSLayer_LoadSongFinishedInt As Long
  #End If
Private ctSSLayer_UnloadSongInt As Long
#If ctSSLayer_GetInfoString Then
  Private ctSSLayer_GetInfoStringInt As Long
  #End If
#If ctSSLayer_GetPosition Then
  Private ctSSLayer_GetPositionInt As Long
  #End If
#If ctSSLayer_SeekSong Then
  Private ctSSLayer_SeekSongInt As Long
  #End If
#If ctSSLayer_SetPause Then
  Private ctSSLayer_SetPauseInt As Long
  #End If
#If ctSSLayer_SetVolume Then
  Private ctSSLayer_SetVolumeInt As Long
  #End If
#If ctSSLayer_GetSongLength Then
  Private ctSSLayer_SongLengthInt As Long
  #End If


[CODE]
Public Function ctSSLayer_LoadVB(ParamArray CustomDLLFilenames()) As Long
  Dim xLong1 As Long
  '1=ok/versionid, -1=no dll, 0=incompatible
  
  For xLong1 = 0& To UBound(CustomDLLFilenames())
    hModul = LoadLibrary(CStr(CustomDLLFilenames(xLong1)))
    If Not hModul = 0& Then Exit For
    Next
  
  If hModul = 0& Then
    ctSSLayer_LoadVB = -1&
    Else
    xLong1 = GetProcAddress(hModul, "ctSSLayer_Version")
    If xLong1 = 0& Then
      Call FreeLibrary(hModul)
      ctSSLayer_LoadVB = 0&
      Else
      ctSSLayer_LoadVB = CallFunction_Fast(xLong1, LayerVersionID)
      If ctSSLayer_LoadVB = 0& Then
        Call FreeLibrary(hModul)
        Else
        ctSSLayer_CanUseItemInt = GetProcAddress(hModul, "ctSSLayer_CanUseItem")
        If IsUnicode Then
          #If ctSSLayer_Devices Then
            ctSSLayer_GetDeviceNameInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceNameW")
            ctSSLayer_GetDeviceSSLIDInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceSSLIDW")
            #End If
          #If ctSSLayer_GetInfoString Then
            ctSSLayer_GetInfoStringInt = GetProcAddress(hModul, "ctSSLayer_GetInfoStringW")
            #End If
          ctSSLayer_LoadSongInt = GetProcAddress(hModul, "ctSSLayer_LoadSongW")
          #If ctSSLayer_ReadSongInfo Then
            ctSSLayer_ReadSongInfoInt = GetProcAddress(hModul, "ctSSLayer_ReadSongInfoW")
            #End If
          Else
          #If ctSSLayer_Devices Then
            ctSSLayer_GetDeviceNameInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceNameA")
            ctSSLayer_GetDeviceSSLIDInt = GetProcAddress(hModul, "ctSSLayer_GetDeviceSSLIDA")
            #End If
          #If ctSSLayer_GetInfoString Then
            ctSSLayer_GetInfoStringInt = GetProcAddress(hModul, "ctSSLayer_GetInfoStringA")
            #End If
          ctSSLayer_LoadSongInt = GetProcAddress(hModul, "ctSSLayer_LoadSongA")
          #If ctSSLayer_ReadSongInfo Then
            ctSSLayer_ReadSongInfoInt = GetProcAddress(hModul, "ctSSLayer_ReadSongInfoA")
            #End If
          End If
        #If ctSSLayer_GetPosition Then
          ctSSLayer_GetPositionInt = GetProcAddress(hModul, "ctSSLayer_GetPosition")
          #End If
        #If ctSSLayer_Spectrum Then
          ctSSLayer_GetSpectrumInt = GetProcAddress(hModul, "ctSSLayer_GetSpectrum")
          #End If
        #If ctSSLayer_LoadSongAbort Then
          ctSSLayer_LoadSongAbortInt = GetProcAddress(hModul, "ctSSLayer_LoadSongAbort")
          #End If
        #If ctSSLayer_LoadSongFinished Then
          ctSSLayer_LoadSongFinishedInt = GetProcAddress(hModul, "ctSSLayer_LoadSongFinished")
          #End If
        ctSSLayer_LoadSongPlayInt = GetProcAddress(hModul, "ctSSLayer_LoadSongPlay")
        #If ctSSLayer_MusicGetPattern Then
          ctSSLayer_MusicGetPatternInt = GetProcAddress(hModul, "ctSSLayer_MusicGetPattern")
          #End If
        #If ctSSLayer_MusicGetPatterns Then
          ctSSLayer_MusicGetPatternsInt = GetProcAddress(hModul, "ctSSLayer_MusicGetPatterns")
          #End If
        #If ctSSLayer_MusicHasFinished Then
          ctSSLayer_MusicHasFinishedInt = GetProcAddress(hModul, "ctSSLayer_MusicHasFinished")
          #End If
        #If ctSSLayer_MusicTime Then
          ctSSLayer_MusicTimeInt = GetProcAddress(hModul, "ctSSLayer_MusicTime")
          #End If
        #If ctSSLayer_SeekSong Then
          ctSSLayer_SeekSongInt = GetProcAddress(hModul, "ctSSLayer_SeekSong")
          #End If
        #If ctSSLayer_SetPause Then
          ctSSLayer_SetPauseInt = GetProcAddress(hModul, "ctSSLayer_SetPause")
          #End If
        #If ctSSLayer_SetVolume Then
          ctSSLayer_SetVolumeInt = GetProcAddress(hModul, "ctSSLayer_SetVolume")
          #End If
        #If ctSSLayer_GetSongLength Then
          ctSSLayer_SongLengthInt = GetProcAddress(hModul, "ctSSLayer_SongLength")
          #End If
        ctSSLayer_UnloadSongInt = GetProcAddress(hModul, "ctSSLayer_UnloadSong")
        End If
      End If
    End If
  End Function

Public Sub ctSSLayer_UnLoadVB()
  If Not hModul = 0& Then
    Call CallFunction_Indirect(hModul, "ctSSLayer_DllRelease")
    Call FreeLibrary (hModul)
    hModul = 0&
    End If
  End Sub

Public Function ctSSLayer_CanUseItem(ByVal Index As Long) As Long
  ctSSLayer_CanUseItem = CallFunction_Fast(ctSSLayer_CanUseItemInt, Index)
  End Function

Public Sub ctSSLayer_Close(ByVal Fast As Long)
  Call CallFunction_Indirect(hModul, "ctSSLayer_Close", Fast)
  End Sub

#If ctSSLayer_GetInfoString Then
  Public Function ctSSLayer_GetInfoString(ByVal Index As Long) As String
    ctSSLayer_GetInfoString = PeekS(CallFunction_Fast(ctSSLayer_GetInfoStringInt, Index))
    End Function
  #End If

#If ctSSLayer_GetPosition Then
  Public Function ctSSLayer_GetPosition(ByVal SongPointer As Long) As Long
    ctSSLayer_GetPosition = CallFunction_Fast(ctSSLayer_GetPositionInt, SongPointer)
    End Function
  #End If

Public Function ctSSLayer_Init(ByVal OutputDeviceID As Long, ByVal hWnd As Long, ByVal UseCDDA As Long, ByVal UseJitterCorrection As Long) As Long
  ctSSLayer_Init = CallFunction_Indirect(hModul, "ctSSLayer_Init", OutputDeviceID, hWnd, UseCDDA, UseJitterCorrection)
  End Function

Public Function ctSSLayer_LoadSong(ByVal Mode As Long, ByVal Filename As String, ByVal Flags As Long) As Long
  Dim xLong1 As Long

  If IsUnicode Then
    ctSSLayer_LoadSong = CallFunction_Fast(ctSSLayer_LoadSongInt, Mode, StrPtr(Filename), Flags)
    Else
    xLong1 = LocalAllocFromString(Filename)
    If Not xLong1 = 0& Then
      ctSSLayer_LoadSong = CallFunction_Fast(ctSSLayer_LoadSongInt, Mode, xLong1, Flags)
      Call LocalFree(xLong1)
      End If
    End If
  End Function

#If ctSSLayer_LoadSongAbort Then
  Public Sub ctSSLayer_LoadSongAbort(ByVal SongPointer As Long)
    Call CallFunction_Fast(ctSSLayer_LoadSongAbortInt, SongPointer)
    End Sub
  #End If

#If ctSSLayer_LoadSongFinished Then
  Public Function ctSSLayer_LoadSongFinished(ByVal SongPointer As Long) As Long
    ctSSLayer_LoadSongFinished = CallFunction_Fast(ctSSLayer_LoadSongFinishedInt, SongPointer)
    End Function
  #End If

Public Function ctSSLayer_LoadSongPlay(ByVal SongPointer As Long, ByVal Volume As Long, ByVal LoopSong As Long, ByVal Panning As Long, ByVal Paused As Long) As Long
  ctSSLayer_LoadSongPlay = CallFunction_Fast(ctSSLayer_LoadSongPlayInt, SongPointer, Volume, LoopSong, Panning, Paused)
  End Function

Public Function ctSSLayer_PreInit(ByVal hWnd As Long) As Long
  ctSSLayer_PreInit = CallFunction_Indirect(hModul, "ctSSLayer_PreInit", hWnd)
  End Function

#If ctSSLayer_SeekSong Then
  Public Function ctSSLayer_SeekSong(ByVal SongPointer As Long, ByVal SeekPosition As Long) As Long
    ctSSLayer_SeekSong = CallFunction_Fast(ctSSLayer_SeekSongInt, SongPointer, SeekPosition)
    End Function
  #End If

#If ctSSLayer_SetPause Then
  Public Sub ctSSLayer_SetPause(ByVal SongPointer As Long, ByVal Pause As Long)
    Call CallFunction_Fast(ctSSLayer_SetPauseInt, SongPointer, Pause)
    End Sub
  #End If

#If ctSSLayer_SetVolume Then
  Public Sub ctSSLayer_SetVolume(ByVal SongPointer As Long, ByVal Volume As Long)
    Call CallFunction_Fast(ctSSLayer_SetVolumeInt, SongPointer, Volume)
    End Sub
  #End If

#If ctSSLayer_GetSongLength Then
  Public Function ctSSLayer_SongLength(ByVal SongPointer As Long) As Long
    ctSSLayer_SongLength = CallFunction_Fast(ctSSLayer_SongLengthInt, SongPointer)
    End Function
  #End If

Public Sub ctSSLayer_UnloadSong(ByVal SongPointer As Long)
  Call CallFunction_Fast(ctSSLayer_UnloadSongInt, SongPointer)
  End Sub
