【发布时间】:2013-12-05 08:53:02
【问题描述】:
我正在尝试使用这个功能(它需要),所以我正在编写这样的代码:
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
private static void OnEvent(MyEvent ev)
{
string sound = Path.Combine(SoundFolder, ev.SoundName) + ".mp3";
var command = string.Format("open {0} type mpegvideo alias sound", sound);
mciSendString(command, null, 0, IntPtr.Zero);
mciSendString("play all", null, 0, IntPtr.Zero);
new NotificationPage(ev).Show();
}
但它不播放任何东西,即使是带有硬编码路径的文件。我做错了什么?
添加:我重写了方法以使用 int 来代替 long。 但它仍然无法正常工作。 即使是简单的代码:
public MainWindow()
{
InitializeComponent();
string sound = Path.Combine(SoundFolder, "NormalPriority") + ".mp3";
if (!File.Exists(sound))
throw new FileNotFoundException();
var command = string.Format("open {0} type mpegvideo alias sound", sound);
mciSendString(command, null, 0, IntPtr.Zero);
mciSendString("play all", null, 0, IntPtr.Zero);
}
所以它是一个 WPF 应用程序
原来是这样的
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
_notificator = new Notificator(Directory.GetCurrentDirectory());
_notificator.EventStarted += (o, ev) => Dispatcher.Invoke(() => OnEvent(ev));
...
我在 C++ 2 上写的
#include <windows.h>
#include <mmsystem.h>
#pragma comment (lib, "winmm.lib")
#include <string>
int main()
{
int res = mciSendString(L"open D:\\song.mp3 type mpegvideo alias sound", NULL, 0, 0);
printf("%i", res);
return 0;
}
同样的错误 277
【问题讨论】:
标签: c# .net winapi pinvoke dllimport