最近需要开发一个简单的wince程序放在Honeywell手持终端上运行,特定逻辑下需要播放错误提示的声音文件,
发现如果是wince6环境下可以直接实现,但Honeywell Dolphin6100只支持wince5,没有现成的函数可调用。
后来在Honeywell官网的SDK中找到了解决办法。
1.在VS2008下建立工程
2.选择wince
3.在HoneyWell官网下载SDK(Honeywell D6X00 Device SDK for WinCE 5.0 Setup r108.zip),安装
4.在安装目录下找到Honeywell.DataCollection.WinCE.Common.dll,参照进工程
5.代码
Honeywell.PDTDevice.UtilMethods.PlaySound("error.wav")
另外,SDK示例中还给出了一个播放声音文件的class
clsSound:
Imports System
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Imports System.Threading
Imports System.IO
Public Class clsSound
Private m_soundBytes As Byte()
Private m_fileName As String
Private Enum Flags
SND_SYNC = 0
SND_ASYNC = 1
SND_NODEFAULT = 2
SND_MEMORY = 4
SND_LOOP = 8
SND_NOSTOP = 16
SND_NOWAIT = 8192
SND_ALIAS = 65536
SND_ALIAS_ID = 1114112
SND_FILENAME = 131072
SND_RESOURCE = 262148
End Enum
' play synchronously (default)
' play asynchronously
' silence (!default) if sound not found
' pszSound points to a memory file
' loop the sound until next sndPlaySound
' don't stop any currently playing sound
' don't wait if the driver is busy
' name is a registry alias
' alias is a predefined ID
' name is file name
' name is resource name or atom
<DllImport("CoreDll.DLL", EntryPoint:="PlaySound", SetLastError:=True)> _
Private Shared Function WCE_PlaySound(ByVal szSound As String, ByVal hMod As IntPtr, ByVal flags As Integer) As Integer
End Function
<DllImport("CoreDll.DLL", EntryPoint:="PlaySound", SetLastError:=True)> _
Private Shared Function WCE_PlaySoundBytes(ByVal szSound As Byte(), ByVal hMod As IntPtr, ByVal flags As Integer) As Integer
End Function
''' <summary>
''' Construct the Sound object to play sound data from the specified file.
''' </summary>
Public Sub New(ByVal fileName As String)
m_fileName = fileName
End Sub
''' <summary>Construct the Sound object to play sound data from the specified stream. </summary>
Public Sub New(ByVal stream As Stream)
' read the data from the stream
m_soundBytes = New Byte(stream.Length) {}
stream.Read(m_soundBytes, 0, stream.Length)
End Sub
''' <summary> Play the sound </summary>
Public Sub Play()
' if a file name has been registered, call WCE_PlaySound,
' otherwise call WCE_PlaySoundBytes
If m_fileName IsNot Nothing Then
WCE_PlaySound(m_fileName, IntPtr.Zero, DirectCast((Flags.SND_ASYNC Or Flags.SND_FILENAME), Integer))
Else
WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, DirectCast((Flags.SND_ASYNC Or Flags.SND_MEMORY), Integer))
End If
End Sub
End Class
调用方法:
Dim mySound As New clsSound("error.wav")
mySound.Play()