【发布时间】:2014-01-30 16:53:37
【问题描述】:
点击按钮时我需要播放声音。我找到了这个 C++ 中的 dll。所以我用p invoke,但是弹出一个错误:
错误 2 最好的重载方法匹配 'WinCE.Sound.PlaySound(string, System.IntPtr, int)' 有一些无效 参数 C:\Users\Fero\Documents\route-loader-recorder\WinCE\Sound.cs 44 17 WinCE
还有这个:
错误 3 参数“3”:无法从“WinCE.PlaySoundFlags”转换为 'int' C:\Users\Fero\Documents\route-loader-recorder\WinCE\Sound.cs 44 51 WinCE
有什么想法吗?
我的代码是:
namespace Sound
{
public enum PlaySoundFlags : int {
SND_SYNC = 0x0, // play synchronously (default)
SND_ASYNC = 0x1, // play asynchronously
SND_NODEFAULT = 0x2, // silence (!default) if sound not found
SND_MEMORY = 0x4, // pszSound points to a memory file
SND_LOOP = 0x8, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x10, // don't stop any currently playing sound
SND_NOWAIT = 0x2000, // don't wait if the driver is busy
SND_ALIAS = 0x10000, // name is a registry alias
SND_ALIAS_ID = 0x110000,// alias is a predefined ID
SND_FILENAME = 0x20000, // name is file name
SND_RESOURCE = 0x40004, // name is resource name or atom
};
public class Sound
{
[DllImport("winmm.dll", SetLastError = true)]
public static extern int PlaySound(
string szSound,
IntPtr hModule,
int flags);
public static void Beep() {
Play(@"\Windows\Voicbeep");
}
public static void Play(string fileName) {
try {
PlaySound(fileName, IntPtr.Zero, (PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_SYNC));
} catch (Exception ex) {
MessageBox.Show("Can't play sound file. " + ex.ToString());
}
}
}
}
【问题讨论】:
-
@ctacke 这是一个纯粹的 P/Invoke 问题,您不应该删除该标签
标签: c# compact-framework pinvoke windows-ce