2 wuhulahei 123 wuhulahei_123 于 2015.06.29 22:03 提问

“PlaySound.DllImportAttribute”不包含采用“1”个参数的

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

//引用新的命名空间,以调用windows系统自带的PlaySound函数
namespace PlaySound
{

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    //读者只需要知道使用这种方法使用PlaySound()就可以!
    //播放响应用户操作的声音和背景音乐,前者使用Windows系统自带的播放声音的函数PlaySound,而背景音乐的播放则使用Windows Media Play控件

    public DllImport



    [DllImport("winmm")]  

    public static extern bool PlaySound(string szSound,int hMod,int i);


    private void Play(string waveName)
    {
         PlaySound(Application.StartupPath +"\\"+waveName,0,1);
    }
     private void PlayMusic(string musicName)
     {
         this.axWindowsMediaPlayer1.URL ="";
         this.axWindowsMediaPlayer1.URL =Application.StartupPath+"\\"+musicName;
     }
    private void Button1_Click(object sender, EventArgs e)
    {
    this.Play("Shot.wav");        

    }
    private void Button2_Click(object sender, EventArgs e)
    {
        this.PlayMusic("town.mid");
    }
}   

}
错误 “PlaySound.DllImportAttribute”不包含采用“1”个参数的构造函数

2个回答

danielinbiti
danielinbiti   Ds   Rxr 2015.06.29 22:10
 public const int SND_FILENAME = 0x00020000;
    public const int SND_ASYNC = 0x0001;
        PlaySound(Application.StartupPath +"\\"+waveName,0,SND_ASYNC|SND_FILENAME);
caozhy
caozhy   Ds   Rxr 2015.06.30 00:18

public DllImport
这是什么东西,删除。

Csdn user default icon
上传中...
上传图片
插入图片