我有一個應用程序,它基本上是做了三兩件事:訪問衝突 - WINMM.DLL ntdll.dll中
- 顯示給用戶
- 播放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());
}
}
}
讓我知道,如果有其他相關細節,我應該包括...
您定義P/Invoke簽名的方式以及您調用方式的源代碼可能會有所幫助。 – 2011-04-13 21:03:06
如果代碼正在執行P/Invoke,則不能確定該程序正在.NET虛擬機中運行(僅限於)。這就像說:「當他入獄時(囚犯打開門),囚犯怎麼會這樣做」 – 2011-04-13 21:03:30
在我們弄清楚發生了什麼事之前,我們需要一個* native * call stack。爲了得到這個,下載Debugging Tools for Windows,運行WinDbg,「Attach to Process」,然後輸入'.symfix; kn100'進入命令窗口 – 2011-04-13 21:11:12