[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/09/2009 at 09:52AM PDT, ID: 24718803
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Windows Error Codes and COM error codes

Asked by cebasso in Delphi Programming, Windows ATL / WTL / COM Programming, C++ Programming Language

Tags: Delphi COM Error Codes HRESULT Facility Severity

Hello!!

I'm implementing in my application a system of error codes based on Windows like HRESULT!

As i see, HRESULT is common used in COM, but basically is the same way like Windows does in some functions...

Looking in winerror.h i got the structure of each type like bellow in Code...

But for HRESULT, Windows.pas provide a way to do that and check everything like bellow:

{ Translated from WINERROR.H }

function Succeeded(Status: HRESULT): BOOL;
begin
  Result := Status and HRESULT($80000000) = 0;
end;

function Failed(Status: HRESULT): BOOL;
begin
  Result := Status and HRESULT($80000000) <> 0;
end;

function IsError(Status: HRESULT): BOOL;
begin
  Result := (Status shr 31) = SEVERITY_ERROR;
end;

function HResultCode(hr: HRESULT): Integer;
begin
  Result := hr and $0000FFFF;
end;

function HResultFacility(hr: HRESULT): Integer;
begin
  Result := (hr shr 16) and $00001FFF;
end;

function HResultSeverity(hr: HRESULT): Integer;
begin
  Result := (hr shr 31) and $00000001;
end;

function MakeResult(sev, fac, code: Integer): HResult;
begin
  Result := (sev shl 31) or (fac shl 16) or code;
end;

function HResultFromWin32(x: Integer): HRESULT;
begin
  Result := x;
  if Result <> 0 then
    Result := ((Result and $0000FFFF) or
      (FACILITY_WIN32 shl 16) or HRESULT($80000000));
end;

function HResultFromNT(x: Integer): HRESULT;
begin
  Result := x or FACILITY_NT_BIT;
end;

Example:

function MyFunction(lpData: PChar): Longint; StdCall;
begin
  if EmptyPChar(lpData) then
  begin
    Result := MakeResult(SEVERITY_ERROR, FACILITY_WIN32, ERROR_INVALID_PARAMETER);
    Exit;
  end;
  ...

But its for generate a HRESULT, and for generate Windows Error code, with the correct SEVERITY like:
00 - Success
01 - Informational
01 - Informational
10 - Warning
11 - Error
and correct Structure for generate this error, somebody knows?

Best Regards,
Carlos
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
// Windows Error Codes (Like used in Reg functions...)
//
//  Values are 32 bit values layed out as follows:
//
//   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
//   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
//  +---+-+-+-----------------------+-------------------------------+
//  | Sev | C | R |      Facility          |               Code                  |
//  +---+-+-+-----------------------+-------------------------------+
//
//  where
//
//      Sev - is the severity code
//
//          00 - Success
//          01 - Informational
//          10 - Warning
//          11 - Error
//
//      C - is the Customer code flag
//
//      R - is a reserved bit
//
//      Facility - is the facility code
//
//      Code - is the facility's status code
//
//
// Define the facility codes
//
 
and for HRESULT in COM
 
////////////////////////////////////
//                                         //
//     COM Error Codes            //
//                                    //
////////////////////////////////////
 
//
// The return value of COM functions and methods is an HRESULT.
// This is not a handle to anything, but is merely a 32-bit value
// with several fields encoded in the value.  The parts of an
// HRESULT are shown below.
//
// Many of the macros and functions below were orginally defined to
// operate on SCODEs.  SCODEs are no longer used.  The macros are
// still present for compatibility and easy porting of Win16 code.
// Newly written code should use the HRESULT macros and functions.
//
 
//
//  HRESULTs are 32 bit values layed out as follows:
//
//   3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
//   1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
//  +-+-+-+-+-+---------------------+-------------------------------+
//  | S | R | C | N | r |      Facility         |               Code                |
//  +-+-+-+-+-+---------------------+-------------------------------+
//
//  where
//
//      S - Severity - indicates success/fail
//
//          0 - Success
//          1 - Fail (COERROR)
//
//      R - reserved portion of the facility code, corresponds to NT's
//              second severity bit.
//
//      C - reserved portion of the facility code, corresponds to NT's
//              C field.
//
//      N - reserved portion of the facility code. Used to indicate a
//              mapped NT status value.
//
//      r - reserved portion of the facility code. Reserved for internal
//              use. Used to indicate HRESULT values that are not status
//              values, but are instead message ids for display strings.
//
//      Facility - is the facility code
//
//      Code - is the facility's status code
//
 
//
// Severity values
//
 
Keywords: Windows Error Codes and COM error …
 
Loading Advertisement...
 
[+][-]09/09/09 10:04 AM, ID: 25293309

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Delphi Programming, Windows ATL / WTL / COM Programming, C++ Programming Language
Tags: Delphi COM Error Codes HRESULT Facility Severity
Sign Up Now!
Solution Provided By: jkr
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09/09/09 10:39 AM, ID: 25293694

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625