Win32 PlaySound problem 
Author Message
 Win32 PlaySound problem

Hi All,

I can1t get the PaySound call in the Windows WINMM.DLL to work. Depending on
the flag, the function (1) returns an error, i.e. FALSE, or (2) returns TRUE
but plays the default system alert sound, rather than the specified sound. I
tried a lot of things, none of them worked. I am not even certain which of
the three parameters I have wrong.  I am suspicious that 3wHandle.long(0) =
&h000000002 is not a nil pointer. I tried to use the ptr property of
memoryBlock, but got nowhere.

Any suggestion would be welcome.

Below is the module that does not work.

------------------------------------------------

Sub PlayWavFile(fileName as string)

  // fileName is GetOpenFolderItem("wavFile").name

  dim n as integer
  dim b as boolean
  dim wFileName, wHandle, wSoundFlag as memoryBlock
  dim i, x as integer

  wSoundFlag = newMemoryBlock(4)

   // ***** SND_NODEFAULT - SoundPlay returns error
  'wSoundFlag.long(0) = &h02

  // *****  SND_ASYNC - no error, but function plays default system sound
  'wSoundFlag.long(0) = &h01

  // *****  SND_SYNC - SoundPlay returns error
  wSoundFlag.long(0) = &h00

  // *****  make wHandle a nil pointer
  wHandle = newMemoryBlock(4)
  wHandle.long(0) = &h00000000

  // ***** convert fileName into a C string
  n = len(fileName) + 1 // add 1 for the terminating 0 in C string
  wFileName = newMemoryBlock(n)
  for i = 1 to n - 1
    wFileName.byte(i - 1) = asc(mid(fileName, i ,1))
  next
  wFileName.byte(n-1) = &h00

  #if TargetWin32 then
     declare function PlaySound Lib "WINMM.DLL" alias "PlaySoundA" (byVal
wFileName as string,  byVal wHandle as integer, byVal wSoundFlag as integer)
as boolean  
  #endif

  b = PlaySound(wFileName.cString(0), wHandle.long(0), wSoundFlag.long(0))

  if b = false then
    MainWindow.lblDebug.text = "PlaySound function error"
  else
    MainWindow.lblDebug.text = "sound is playing"
  end if

End Sub



Thu, 29 Jan 2004 10:12:31 GMT  
 Win32 PlaySound problem


Quote:
>I tried to use the ptr property of memoryBlock, but got nowhere.

I found out how to use the ptr property, thanks to Matt Neuberg p.160
(The ptr property can only be used on the left side of an assignment when
the right side is also a memoryBlock.)

here is the revised nul pointer code:

  dim nulBlock, nulPointer, nulHandle as memoryBlock

  nulBlock = newMemoryBlock(4)
  nulPointer = newMemoryBlock(4)
  nulHandle = newMemoryBlock(4)

  nulBlock.long(0) = &h00000000
  nulPointer.ptr(0) = nulBlock
  nulHandle.ptr(0) = nulPointer

Question: does this make the variable nullHandle a null Handle, or should it
be:

 nulHandle.ptr(0) = nulBlock

Bad News: The Win32 call still does not work with either of the two
nulHandle assignments.

Question: Does anyone know the value of the Win32 Winmm constant
"SND_FILENAME"?



Tue, 03 Feb 2004 02:33:40 GMT  
 Win32 PlaySound problem


Quote:
> here is the revised nul pointer code:

> dim nulBlock, nulPointer, nulHandle as memoryBlock

> nulBlock = newMemoryBlock(4)
> nulPointer = newMemoryBlock(4)
> nulHandle = newMemoryBlock(4)

> nulBlock.long(0) = &h00000000
> nulPointer.ptr(0) = nulBlock
> nulHandle.ptr(0) = nulPointer

> Question: does this make the variable nullHandle a null Handle, or should it
> be:

> nulHandle.ptr(0) = nulBlock

Answer: Either one works
Quote:

> Question: Does anyone know the value of the Win32 Winmm constant
> "SND_FILENAME"?

Answer: &h20000
        use the bitwiseOr function to combine two flags at a time, e.g.
        f = bitwiseOr(f1, f2)
        f = fitwiseOr(f, f3)
        etc.

Several hours of experimenting yielded the answers
Function now works OK



Tue, 10 Feb 2004 09:56:51 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Gnat linking problem to Microsoft Visual C++ V6.0 (PlaySound)

2. Where is PlaySound?

3. . Where is PlaySound?

4. PlaySound() followup question...... JohnDeV

5. PlaySound() in Cobol

6. PlaySound API

7. calling Microsoft PlaySound routine from CVF

8. Newbie Question on PlaySound

9. elj-win32 0.4 Release: The GNU Eiffel win32 Distribution

10. elj-win32: A FREE/NO-RISK win32 SmallEiffel Distribution

11. Calling Win32 API functions with Gnat 3.09 (Win32 version)

12. Win32 extensions using the .NET SDK and the Win32 Platform SDK

 

 
Powered by phpBB® Forum Software