VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "cSound"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long
Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Ptr() As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    
Private f_bvSound() As Byte

Public Function LoadFromRes(ByVal vID As Variant, ByVal vType As Variant, Optional ByVal VBglobal As IUnknown) As Boolean
    Dim oWorkSpace As VB.Global
    
    On Local Error GoTo LoadFromRes_Error

    If VBglobal Is Nothing Then
        Set oWorkSpace = VB.Global
    ElseIf TypeOf VBglobal Is VB.Global Then
        Set oWorkSpace = VBglobal
    Else
        Set oWorkSpace = VB.Global
    End If
    
    f_bvSound = oWorkSpace.LoadResData(vID, vType)
    If IsArrayDim(VarPtrArray(f_bvSound)) Then
        LoadFromRes = True
    End If

    On Error GoTo 0
    Exit Function
LoadFromRes_Error:
End Function

Public Function LoadFromFile(ByVal sFIle As String) As Boolean
    On Local Error GoTo LoadFromFile_Error

    If Not PathFileExists(sFIle) = 0 Then
        Open sFIle For Binary Access Read As #1
        ReDim f_bvSound(LOF(1) - 1)
        Get #1, , f_bvSound
        Close #1
    End If

    LoadFromFile = True

    On Error GoTo 0
    Exit Function

LoadFromFile_Error:
End Function

Friend Function GetBytes() As Byte()
    GetBytes = f_bvSound
End Function

Private Function IsArrayDim(ByVal lpArray As Long) As Boolean
    Dim lAddress As Long
    
    Call CopyMemory(lAddress, ByVal lpArray, &H4)
    IsArrayDim = Not (lAddress = 0)
End Function

Private Sub Class_Initialize()
'
End Sub

Private Sub Class_Terminate()
    Erase f_bvSound
End Sub
