我在 Windows7 和 VS2010 上使用 .Net 3.5 用 C# 编写了 32 位代码,并且运行没有任何问题,现在我使用 .Net 4.0 将其转换为 64 位,但当我的代码调用 CloseHandle 时出现错误。
错误 - 关闭句柄
System.Runtime.InteropServices.SEHException (0x80004005):外部组件引发异常。
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
关闭?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)