我知道这是有点古老,但花了相当多的时间试图找到一个完整的答案没有成功。所以我想我会分享我的想法。
发生这种情况的完整答案是当您调用“失败”的pInvoke方法但不是因为错误。
搞起你认为
例如假设你需要解开一个窗钩,但这样做的因位的意大利面条或在你的对象架构防御式编程的偏执水平打了两次电话。
// hook assigned earlier
// now we call our clean up code
if (NativeMethods.UnhookWindowsHookEx(HookHandle) == 0)
{
// method succeeds normally so we do not get here
Log.ReportWin32Error("Error removing hook", Marshal.GetLastWin32Error());
}
// other code runs, but the hook is never reattached,
// due to paranoid defensive program you call your clean up code twice
if (NativeMethods.UnhookWindowsHookEx(HookHandle) == 0)
{
// pInvoke method failed (return zero) because there was no hook to remove
// however there was no error, the hook was already gone thus ERROR_SUCCESS (0)
// is our last error
Log.ReportWin32Error("Error removing hook", Marshal.GetLastWin32Error());
}
通常,当你的错误代码'0',通常表示成功(如没有问题)。显然,无论你在那里做了什么,都认为出现了问题,并在没有一个问题时打印出“错误信息”。 –
'ERROR_SUCCESS'表示WinAPI中的“无错误”。它的前缀是ERROR_,它与“定义命名空间”相同。我会更加关注IOError位,尽管我不知道是什么原因造成的。 – 2011-09-23 04:49:19