gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-30 01:22:52 27 4
gpt4 key购买 nike

我在 Windows7 和 VS2010 上用 C# 编写了代码,使用 .Net 3.5 的 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 关闭什么?

关于c# - System.Runtime.InteropServices.SEHException (0x80004005) : External component has thrown an exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12589604/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com