Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Windows, is there any way to convert an errno into an HRESULT?

I know the HRESULT_FROM_WIN32 macro to convert a Win32 error code into an HRESULT, is there any way to do the conversion starting from an errno error?

like image 991
Alessandro Jacopson Avatar asked Sep 10 '12 13:09

Alessandro Jacopson


People also ask

Does Errno work on Windows?

The errno values in a 32-bit Windows operating system are a subset of the values for errno in UNIX systems. The errno value isn't necessarily the same as the actual error code returned by a system call from the Windows operating system.

What is S_ok?

The most commonly used success code is S_OK which has value 0. But in rare circumstances, a function returns a success code with additional information such as S_FALSE which has value 1.


1 Answers

In short, no.

As of http://msdn.microsoft.com/en-us/library/5814770t%28v=vs.100%29.aspx

The errno values are constants assigned to errno in the event of various error conditions.

ERRNO.H contains the definitions of the errno values. However, not all the definitions given in ERRNO.H are used in 32-bit Windows operating systems. Some of the values in ERRNO.H are present to maintain compatibility with the UNIX family of operating systems.

The errno values in a 32-bit Windows operating system are a subset of the values for errno in XENIX systems. Thus, the errno value is not necessarily the same as the actual error code returned by a system call from the Windows operating systems. To access the actual operating system error code, use the _doserrno variable, which contains this value.

Of course you can write your own function with switch-cases which will "translate" error codes.

You can see that there are about 80 errno values defined on windows.

like image 81
rkosegi Avatar answered Sep 21 '22 23:09

rkosegi