我需要播放聲音時點擊按鈕。我發現這是在C++中的DLL。所以我用p invoke
,但一個錯誤彈出:PlaySound WinCE
錯誤2的最佳重載的方法匹配 'WinCE.Sound.PlaySound(字符串,System.IntPtr,INT)' 有一些無效 參數C:\用戶\ FERO \文檔\路由架錄像機\ WinCE的\ Sound.cs 44 17 WinCE的
而且也是這樣:
錯誤3參數 '3':無法從「WinCE.PlaySoundFlags轉換'到 'int'C:\ Users \ Fero \ Do cuments \ 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問題,你不應該刪除那個標記 –