如何播放文件名来自系统字符串的声音文件

时间:2013-04-20 14:21:42

标签: visual-studio-2010 c++-cli

String ^ fileName = textBox5->Text + "DES.wav";

PlaySound(fileName, NULL, SND_FILENAME | SND_SYNC);

错误在于:

错误4错误C2664:'PlaySoundW':无法将参数1从'System :: String ^'转换为'LPCWSTR'

1 个答案:

答案 0 :(得分:0)

无需混合托管代码和非托管代码,请使用SoundPlayer类:

String ^ fileName = textBox5->Text + "DES.wav";
SoundPlayer^ player = gcnew SoundPlayer(filename);
player->PlaySync();    // or Play for asynchronous execution

http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx