[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

API and LoadResData function?

hi
we paste my code,below,please elaborate
when clicking command button ,sound wont play.why?



Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Const SND_ASYNC = &H1
Const SND_NODEFAULT = &H2
Private x() As Byte
 Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
SendKeys "%+"
SendKeys "%+"
Text1.Visible = True
Text1.SetFocus
x = LoadResData(101, "AA")
 ing = sndPlaySound(x(0), SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
 Text1.Text = ing
End Sub

Private Sub Form_Click()
End
End Sub

Private Sub Timer1_Timer()
a = Int(Rnd * 255)
b = Int(Rnd * 255)
c = Int(Rnd * 255)
Label1.ForeColor = RGB(a, b, c)
Form1.BackColor = RGB(c, a, b)
Label1.FontSize = Int(Rnd * 60) + 10
End Sub


thanks
0
asdf246
Asked:
asdf246
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
The sndPlaySound API expects to be passed a string telling it what file to play, not a byte array.

You could read your res file, write that data to a temp file, and then play the temp file.

    Dim data() As Byte
    data = LoadResData(101, "AA") ' or use
    Open "Temp.wav" For Binary Access Write As #1
    Put #1, , data
    Close #1
    sndPlaySound "Temp.wav", SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY

Just delete the file when you are done with it.  I'm sure if there is a way to directly play a file stored in a byte array in memory.

Idle_Mind
0
 
vinnyd79Commented:
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now