如何查找正确的 Windows 系统错误代码以在我的应用程序中使用?
我正在编写一个 C# .NET 2.0 应用程序,其中预计将通过 SerialPort
接收消息。如果未收到帧(即超时)或确定帧无效,我需要使用 SetLastError
设置错误代码。 Windows 有大量错误代码。是否有一个简单的工具或参考来帮助缩小要使用的正确错误代码的范围?
附加信息
虽然我更喜欢抛出异常并在堆栈的更高层处理它,但在这种情况下这不是一个选项,因为我正在更新的应用程序并非设计为采用利用这样一个有用的功能。
I am writing a C# .NET 2.0 application wherein when a message is expected to be received via the SerialPort
. If the frame is not received (i.e. times out) or it is determined to be invalid, I need to set an error code using SetLastError
. Windows has a plethora of error codes. Is there a simple tool or reference to help narrow down the proper error code to use?
ADDITIONAL INFO
While throwing an exception and handling it higher up the stack is my preference, that is not an option in this case because the application I am updating was not designed to take advantage of such a useful feature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不幸的是,上面的方法对我不起作用,但这对我来说非常有效,粘贴整个代码,以便可以直接在 C# 中复制粘贴
Unfortunately the above didn't work for me, however this worked perfectly for me, pasting the whole code so it can be copy pasted directly in C#
在“美好的过去”(C 和 C++)中,可能的 Windows 错误列表是在 winerror.h 中定义的
更新: 下面的链接已失效。不确定该文件是否仍然可供下载,但所有 Windows 系统错误代码定义可以在此链接中找到。
该文件可以在 Microsoft 网站 上找到(尽管它让我有点惊讶)它的历史可以追溯到 2003 年 - 可能值得寻找更新的版本)。
但是,如果您收到(或想要设置)Win32 错误代码,则可以在此处找到定义。
in the "good old days" (C and C++), the list of possible Windows errors was defined in winerror.h
UPDATE: Link below is dead. Not sure if the file is still available for download, but all the Windows System Error Code definitions can be found at this link.
This file can be found on Microsoft's site (although it surprises me a little that it is dated as far back as 2003 - might be worth hunting for a more recent version).
But if you're getting (or wanting to set) Win32 error codes, this'll be where the definition is found.
您可以在这里找到所有这些内容的列表:
http://en.kioskea .net/faq/2347-error-codes-in-windows
然后只需搜索“串行”并使用最适合您的错误的一个
You can find a list of them all here:
http://en.kioskea.net/faq/2347-error-codes-in-windows
Then just do a search for 'Serial' and use whichever one best fits your error