System.Runtime.InteropServices.SEHException(0x80004005):外部组件抛出exception

我在Windows7和VS2010上使用C#编写代码,32位使用.Net 3.5并且运行没有任何问题,现在我使用.Net 4.0将其转换为64位但是当我的代码调用CloseHandle时出现错误。

错误 – CloseHandle
System.Runtime.InteropServices.SEHException(0x80004005):外部组件抛出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); 

任何帮助表示赞赏。

您不能将CloseHandle与指向用户内存的指针一起使用。 您需要分配一个HANDLE才能关闭它。 您对CloseHandle期望是什么?