我有一个应用程序,它基本上做了三件事:
- 向用户显示图像
- 向用户播放 1-2 秒的声音 (wav)
- 录制麦克风输入 4 秒(播放声音时)
每个用户会发生 280 次,所有记录都保存在每个用户的目录中。但是,在该程序的最后 18 次运行中,有 2 次因为模块 ntdll.dll 中代码为 c0000005(被描述为访问冲突)的未处理异常而崩溃。我使用的唯一非托管 api 调用是来自 winmm.dll 的 mciSendString 以获取 wav 文件的持续时间并进行录制。播放是使用 WindowsMediaPlayer 的实例完成的。
崩溃似乎是随机的,并且都发生在同一台机器上(正在使用 3 个)。这些是我的问题:ntdll.dll 真的是异常的来源吗?我是否正确理解访问冲突是无效的内存访问?在 .NET 虚拟机中运行的 C# 程序怎么会发生这种情况?
根据请求,这里是我调用 mciSendString 的一类
public class JE_SR
{
[DllImport("winmm.dll", EntryPoint = "mciSendStringA",
CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
private static extern uint mciSendString(string lpstrCommand,
string lpstrReturnString, int uReturnLength, int hwndCallback);
[DllImport("winmm.dll", CharSet = CharSet.Auto)]
private static extern int mciGetErrorString(uint errorCode,
StringBuilder errorText, int errorTextSize);
private static bool recording = false;
public static uint lastResult;
public static void startRecording()
{
if (recording)
{
return;
}
tryMCISendString("open new Type waveaudio Alias recsound", "", 0, 0);
tryMCISendString("record recsound", "", 0, 0);
recording = true;
}
public static void stopRecording(string file)
{
if (!recording)
{
return;
}
if (!file.Equals(""))
{
tryMCISendString("save recsound " + file, "", 0, 0);
tryMCISendString("close recsound ", "", 0, 0);
}
else
{
tryMCISendString("close all", "", 0, 0);
}
recording = false;
}
public static void tryMCISendString(string lpstrCommand,
string lpstrReturnString, int uReturnLength, int hwndCallback)
{
lastResult = mciSendString(lpstrCommand, lpstrReturnString, uReturnLength, hwndCallback);
StringBuilder error = new StringBuilder(256);
if(lastResult != 0)
{
mciGetErrorString(lastResult, error, error.Length);
JE_Log.logMessage("MCIERROR(JE_SR): " + error.ToString());
}
}
}
让我知道是否还有其他相关细节我应该包括...