日期:2014-05-18  浏览次数:21092 次

高分求教vs2010调用DirectX
Microsoft.DirectX.DirectSound.SecondaryBuffer snd = null;
  Microsoft.DirectX.DirectSound.Device dev = null;
  Microsoft.DirectX.DirectSound.BufferDescription buffDes = null;
在vs2008中编译没问题,在运行的时候会出现“C:\WINDOWS\assembly\GAC\Microsoft.DirectX.DirectSound\1.0.2902.0__31bf3856ad364e35\Microsoft.DirectX.DirectSound.dll”正试图在 OS 加载程序锁内执行托管代码。不要尝试在 DllMain 或映像初始化函数内运行托管代码,这样做会导致应用程序挂起的异常,但是继续运行是没问题的,后来进过设置vs2008,这个异常也不报了。
可我现在vs2010中这么用的时候这个异常它不报了,直接出现假死或者软件直接关闭的问题,请高手指点下,谢谢

------解决方案--------------------
加一段代码到program.cs,如果程序出现直接关闭,会记录错误日志到文件。查看日志找到出错行看看错误在哪里。

话说40分也太少了。

C# code

        static Program()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string strException = string.Format("{0}发生系统异常。\r\n{1}\r\n\r\n\r\n", DateTime.Now, e.ExceptionObject.ToString());
            File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemException.log"), strException);
        }