C#调用winmm.dll来放音乐的示例[转载]
2005-01-26 11:46
555 查看
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace Music
/**//// <summary>
///
/// </summary>
public class Audio
[DllImport("winmm.dll")]
private static extern int mciSendString
(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName
(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength
);
public Audio()
}
public void Play(string FileName)
StringBuilder shortPathTemp = new StringBuilder(255);
int result = GetShortPathName(FileName, shortPathTemp, shortPathTemp.Capacity);
string ShortPath = shortPathTemp.ToString();
mciSendString("open "+ShortPath+" alias song","",0,0);
mciSendString("play song","",0,0);
}
public void Stop()
mciSendString("stop song","",0,0);
}
public void Pause()
mciSendString("pause song","",0,0);
}
public void Close()
mciSendString("close song","",0,0);
}
}
}
using System.Text;
using System.Runtime.InteropServices;
namespace Music
/**//// <summary>
///
/// </summary>
public class Audio
[DllImport("winmm.dll")]
private static extern int mciSendString
(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName
(
[MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,
int shortPathLength
);
public Audio()
}
public void Play(string FileName)
StringBuilder shortPathTemp = new StringBuilder(255);
int result = GetShortPathName(FileName, shortPathTemp, shortPathTemp.Capacity);
string ShortPath = shortPathTemp.ToString();
mciSendString("open "+ShortPath+" alias song","",0,0);
mciSendString("play song","",0,0);
}
public void Stop()
mciSendString("stop song","",0,0);
}
public void Pause()
mciSendString("pause song","",0,0);
}
public void Close()
mciSendString("close song","",0,0);
}
}
}
相关文章推荐
- C# 调用系统winmm.dll 播放音乐wav mp3
- C#调用Delphi Dll返回字符串的示例(使用Move才能拷贝字符串)
- C#调用C语言生成的DLL示例
- IronPython脚本调用C#dll示例
- 【转载】C#调用汇编dll
- C#程序实现动态调用DLL的研究(转载)
- C# 调用C++ DLL 的类型转换(转载版)
- C# 调用 Delphi Dll链接库方法及示例
- C#调用winmm.dll播放声音_中国创造
- C#调用C语言编写的dll示例
- C#调用Python脚本的简单示例,IronPython(转载)
- C#程序实现动态调用DLL的研究(转载)
- 使用C++调用C#的DLL(转载)
- IronPython脚本调用C#dll示例
- 20160711--C# 委托的三种调用示例(同步调用 异步调用 异步回调)【转载】
- IronPython脚本调用C#dll示例
- QT编写DLL给外部程序调用,提供VC/C#/C调用示例(含事件)good
- C#调用C语言生成的DLL示例
- 【转载】C#调用C++ DLL
- (转载)C#程序实现动态调用DLL的研究