- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在 C# 中使用 waveout 来同时播放更多的 wav 文件(至少是不同的文件)。 (SoundPlayer 对象一次只播放一个,我不想为这个简单的目标使用 DirectSound 和 MediaPlayer 对象或任何其他高级技术。)
我将一个工作的 C++ 代码移植到 C# 并且它可以工作(在研究了如何编码和如何调用 native win32 dll-s 以及如何分配和锁定非托管内存之后)但它以某种方式使 vhost.exe 崩溃,我不知道为什么这样做。 (它不会抛出任何异常,只会出现标准的 windows 错误对话框并且程序崩溃并退出。)
有没有人有任何想法?
这是该类的来源:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using XiVo.PlayThrough;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Timers;
namespace RTS
{
class WaveObject
{
protected IntPtr wo;
protected byte[] Adat=null;
protected WaveNative.WaveHdr woh;
protected int pgc;
public class NotAWaveformFileException : Exception
{
public NotAWaveformFileException(string str) : base(str) { }
public NotAWaveformFileException() { }
}
public class WaveFileIsCorruptedException : Exception
{
public WaveFileIsCorruptedException(string str) : base(str) { }
public WaveFileIsCorruptedException() { }
}
public class WaveMapperCouldNotBeOpenedException : Exception
{
public WaveMapperCouldNotBeOpenedException(string str) : base(str) { }
public WaveMapperCouldNotBeOpenedException() { }
}
public WaveObject() {}
public WaveObject(string Fn) : this() { Load(Fn); }
public void Load(string Fn)
{
IntPtr mmio;
NativeMMIO.mmckInfo Main, Sub;
WaveFormat wfx;
StringBuilder str=new StringBuilder(Fn);
int r;
mmio = NativeMMIO.mmioOpen(str,IntPtr.Zero,NativeMMIO.MMIO_READ);
if (mmio == IntPtr.Zero)
{
throw new FileNotFoundException(Fn + "not found!");
}
Main.fccType = NativeMMIO.mmioFOURCC('W', 'A', 'V', 'E');
if (NativeMMIO.mmioDescend(mmio, out Main, IntPtr.Zero, NativeMMIO.MMIO_FINDRIFF) != 0)
{
throw new NotAWaveformFileException();
}
Sub.ckid = NativeMMIO.mmioFOURCC('f', 'm', 't', ' ');
if (NativeMMIO.mmioDescend(mmio, out Sub, out Main, NativeMMIO.MMIO_FINDCHUNK) != 0)
{
throw new WaveFileIsCorruptedException("fmt chunk is not found!");
}
byte[] raw = new byte[Sub.cksize+2];
NativeMMIO.mmioRead(mmio, raw, (int)Sub.cksize);
GCHandle conv = GCHandle.Alloc(raw, GCHandleType.Pinned); // mapping a WaveFormat structure from the byte array
wfx = (WaveFormat)Marshal.PtrToStructure(conv.AddrOfPinnedObject(), typeof(WaveFormat));
conv.Free();
Sub.ckid = NativeMMIO.mmioFOURCC('d', 'a', 't', 'a');
if (NativeMMIO.mmioDescend(mmio, out Sub, out Main, NativeMMIO.MMIO_FINDCHUNK) != 0)
{
throw new WaveFileIsCorruptedException("data chunk is not found!");
}
Adat = new byte[Sub.cksize+2];
NativeMMIO.mmioRead(mmio, Adat, (int)Sub.cksize);
NativeMMIO.mmioClose(mmio, 0);
wfx.cbSize = (short)Marshal.SizeOf(wfx);
unchecked // WAVE_MAPPER is 0xFFFFFFFF and it does not let it convert to int otherwise
{
int res = WaveNative.waveOutOpen(out wo, (int)WaveNative.WAVE_MAPPER, wfx, null, 0, (int)WaveNative.CALLBACK_NULL);
if (res != WaveNative.MMSYSERR_NOERROR)
{
throw new WaveMapperCouldNotBeOpenedException();
}
}
woh.lpData = Marshal.AllocHGlobal((int)Sub.cksize); // alloc memory for the buffer
Marshal.Copy(Adat, 0, woh.lpData, (int)Sub.cksize);
woh.dwBufferLength = (int)Sub.cksize;
woh.dwBytesRecorded = 0;
woh.dwUser = IntPtr.Zero;
woh.dwFlags = 0;
woh.dwLoops = 1000000;
woh.reserved = 0;
woh.lpNext = IntPtr.Zero;
r = WaveNative.waveOutPrepareHeader(wo, ref woh, Marshal.SizeOf(woh));
pgc = System.Environment.TickCount;
}
public void Play()
{
if (System.Environment.TickCount - pgc > 50)
{
if (wo == null) throw new Exception("wo somehow became null.");
int res = WaveNative.waveOutReset(wo);
if (res != WaveNative.MMSYSERR_NOERROR) throw new Exception(string.Format("waveOutReset {0}",res));
res=WaveNative.waveOutWrite(wo, ref woh, Marshal.SizeOf(woh));
if ((res != WaveNative.MMSYSERR_NOERROR) && (res!=33)) throw new Exception(string.Format("waveOutWrite {0}",res));
}
}
~WaveObject()
{
Marshal.FreeHGlobal(woh.lpData); // release memory
}
}
}
最佳答案
经过大量谷歌搜索后,我意识到该错误在 winmm.dll 本身中。在某些情况下,它的辅助线程也会崩溃并关闭主机应用程序。
citation
关于c# - 尝试在 C# 中使 waveout 工作时 vhost.exe 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/810405/
我正在努力处理不同的 R 可执行文件。在批处理文件中运行命令行时,R.exe(带或不带 CMD BATCH 选项)、Rcmd.exe、Rscript.exe 和 Rterm.exe 有什么区别? 两者
这个问题是我之前问题的一个答案的扩展:how to save user registration in the exe... (C#) . 这个想法本身对我来说仍然很新,但它似乎是合理的。我第一次尝试
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 12 年前。 Improve thi
我正在使用 React VR 制作一个 WebVR 应用程序。我将使用 Oculus Rift 和 HTC-Vive 测试该应用程序。我正在使用浏览器 Firefox Nightly 来访问 WebV
当我从 A.exe(位于 c:/my_software/FOLDER_A/A.exe)运行 B.exe(位于 c:/my_software/FOLDER_B/B.exe)时,两者均使用 cx_Free
我有一个以前的程序员留下的exe(GUI),它是在cpp中完成的,但是我需要禁用程序中的一些键盘键,因为当它们被意外击中时,这是不可取的。我正在使用 Windows。 我能否编写一个程序来在 Wind
这不是以下 SO 问题的重复: How do I tell if a win32 application uses the .NET runtime . 如果给定的 exe 文件是 .net exe
我刚刚安装了 ActivePython 3.6 的 64 位版本,发现它包含三个可执行文件,它们报告相同的版本信息,大小相同,但不完全相同,即peer fc.exe。我有 python.exe pyt
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
有哪些方法可以保护exe文件免遭逆向工程。有很多打包工具可以打包exe文件。这种方法在http://c-madeeasy.blogspot.com/2011/07/protecting-your-c-
仅当应用“X”(Inspect.exe | Narrator.exe | Magnify.exe)正在运行时,我才能在 Windows 应用程序中获取一些 IUIAutomationElements。
我正在编写一个创建 Windows 服务的程序。所以我需要两个 .exe 文件——一个用于程序,创建服务,另一个用于服务本身。但是我想将这两个文件合二为一。我有以下想法 - 打开 .exe 文件,我想
我有一个 UWP 应用,我需要从 users %appdata% 文件夹中启动一个 .Exe 文件。 我不知道如何找到 %appdata% 或如何启动 Exe 文件。 我已经查看了所有解决方案,但没有
我最近安装了 Visual Studio 2017,MSBuild.exe 不是应该自带的吗? bash 脚本之一正在调用它,但找不到任何东西。 这是 build.bat 产生错误的部分(您可以看到整
我正在我自己的代码中尝试来自 Mad-collections(用于在 exe 中添加/删除或更新资源的单元)中 Madres 单元的不同功能。这适用于小型资源(小于 50 MB),但对于较大的资源(大
什么是PreEmptive Protection Dotfuscator exe文件的Map.Xml和Dotfuscator1.Xml文件。我应该出于某种原因保留它们,还是项目 exe 文件组装需要它
我最近接手了一个项目,我不确定最后一个人是如何调试这个的......我有两个可执行文件,一个最终运行另一个。我将它们称为 exe1 和 exe2。这些是用 C# 创建的,我使用 Visual Stud
如何从 REBOL 脚本创建 Windows 可执行文件 (.exe)?有任何说明或视频吗? 最佳答案 使用 Rebol 2 最简单的方法是使用 SDK - 尽管这需要花钱购买许可证。该方法称为封装。
我正在尝试打开下载的 .exe 文件,但它在打开后立即关闭。有什么可能的方法可以让我打开它更长的时间来阅读内容。 最佳答案 它可能是一个控制台应用程序而不是一个 GUI 应用程序。使用命令提示符运行
我想运行一个位于以下目录中的应用程序: C:\LCR 12\stu.exe 使用 AutoIt,运行上述 stu.exe 文件的代码是什么? 最佳答案 像这样: Run("C:\LCR 12\stu.
我是一名优秀的程序员,十分优秀!