本文介绍了System.Runtime.InteropServices.SEHException(0X80004005):外部组件发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的代码在C#上的Windows7和VS2010,使用.net 3.5 32位,它是乳宁没有任何问题,现在我把它转换为使用.NET 4.0的64位,但我得到了一个错误,当我的代码调用CloseHandle的

I have code written in C# on a Windows7 and VS2010, 32 bit using .Net 3.5 and it is runing without any problem, now I converted it to 64 bit using .Net 4.0 but I got an error when my code call CloseHandle.

错误 - CloseHandle的结果
System.Runtime.InteropServices.SEHException(0X80004005):外部组件发生异常

ERROR - CloseHandle
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.

unsafe
{
    fixed (byte* p = readBuffer)
    {
         IntPtr intPtr = (IntPtr)p;
         this.ReadFile(ref sourceFile, (ulong)buffer_size, intPtr, ref nNumBytesRead);

         if (intPtr != IntPtr.Zero)
         {
             try
             {
                 FunctionSqudf.CloseHandle(intPtr);
             }
             catch (Exception ex)
             {
                  Hardware.LogHardware.Error("CloseHandle", ex);
             }
         }
      }
  }


    [SecuritySafeCritical]
    [DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern bool CloseHandle(IntPtr hObject);



任何帮助表示赞赏。

Any help is appreciated.

推荐答案

您不能使用 CloseHandle的的指针用户内存。您需要,以关闭它分配一个 HANDLE 。你有什么期望 CloseHandle的关闭?

You can't use CloseHandle with a pointer to user memory. You need to allocate a HANDLE in order to close it. What do you expect CloseHandle to close?

这篇关于System.Runtime.InteropServices.SEHException(0X80004005):外部组件发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 12:45