-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
5,407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
//Copied from Windows API Code Pack 1.1 and modified, mainly for public access to PropertyVariant | ||
//Copyright (c) Microsoft Corporation. All rights reserved. | ||
|
||
namespace TestDriverCodePack | ||
{ | ||
/// <summary> | ||
/// HRESULT Wrapper | ||
/// </summary> | ||
public enum HResult | ||
{ | ||
/// <summary> | ||
/// S_OK | ||
/// </summary> | ||
Ok = 0x0000, | ||
|
||
/// <summary> | ||
/// S_FALSE | ||
/// </summary> | ||
False = 0x0001, | ||
|
||
/// <summary> | ||
/// E_INVALIDARG | ||
/// </summary> | ||
InvalidArguments = unchecked((int)0x80070057), | ||
|
||
/// <summary> | ||
/// E_OUTOFMEMORY | ||
/// </summary> | ||
OutOfMemory = unchecked((int)0x8007000E), | ||
|
||
/// <summary> | ||
/// E_NOINTERFACE | ||
/// </summary> | ||
NoInterface = unchecked((int)0x80004002), | ||
|
||
/// <summary> | ||
/// E_FAIL | ||
/// </summary> | ||
Fail = unchecked((int)0x80004005), | ||
|
||
/// <summary> | ||
/// E_ELEMENTNOTFOUND | ||
/// </summary> | ||
ElementNotFound = unchecked((int)0x80070490), | ||
|
||
/// <summary> | ||
/// TYPE_E_ELEMENTNOTFOUND | ||
/// </summary> | ||
TypeElementNotFound = unchecked((int)0x8002802B), | ||
|
||
/// <summary> | ||
/// NO_OBJECT | ||
/// </summary> | ||
NoObject = unchecked((int)0x800401E5), | ||
|
||
/// <summary> | ||
/// Win32 Error code: ERROR_CANCELLED | ||
/// </summary> | ||
Win32ErrorCanceled = 1223, | ||
|
||
/// <summary> | ||
/// ERROR_CANCELLED | ||
/// </summary> | ||
Canceled = unchecked((int)0x800704C7), | ||
|
||
/// <summary> | ||
/// The requested resource is in use | ||
/// </summary> | ||
ResourceInUse = unchecked((int)0x800700AA), | ||
|
||
/// <summary> | ||
/// The requested resources is read-only. | ||
/// </summary> | ||
AccessDenied = unchecked((int)0x80030005) | ||
} | ||
|
||
/// <summary> | ||
/// Provide Error Message Helper Methods. | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
internal static class CoreErrorHelper | ||
{ | ||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
private const int FacilityWin32 = 7; | ||
|
||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
public const int Ignored = (int)HResult.Ok; | ||
|
||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
/// <param name="win32ErrorCode">The Windows API error code.</param> | ||
/// <returns>The equivalent HRESULT.</returns> | ||
public static int HResultFromWin32(int win32ErrorCode) | ||
{ | ||
if (win32ErrorCode > 0) | ||
{ | ||
win32ErrorCode = | ||
(int)(((uint)win32ErrorCode & 0x0000FFFF) | (FacilityWin32 << 16) | 0x80000000); | ||
} | ||
return win32ErrorCode; | ||
|
||
} | ||
|
||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
/// <param name="result">The error code.</param> | ||
/// <returns>True if the error code indicates success.</returns> | ||
public static bool Succeeded(int result) | ||
{ | ||
return result >= 0; | ||
} | ||
|
||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
/// <param name="result">The error code.</param> | ||
/// <returns>True if the error code indicates success.</returns> | ||
public static bool Succeeded(HResult result) | ||
{ | ||
return Succeeded((int)result); | ||
} | ||
|
||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
/// <param name="result">The error code.</param> | ||
/// <returns>True if the error code indicates failure.</returns> | ||
public static bool Failed(HResult result) | ||
{ | ||
return !Succeeded(result); | ||
} | ||
|
||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
/// <param name="result">The error code.</param> | ||
/// <returns>True if the error code indicates failure.</returns> | ||
public static bool Failed(int result) | ||
{ | ||
return !Succeeded(result); | ||
} | ||
|
||
/// <summary> | ||
/// This is intended for Library Internal use only. | ||
/// </summary> | ||
/// <param name="result">The COM error code.</param> | ||
/// <param name="win32ErrorCode">The Win32 error code.</param> | ||
/// <returns>Inticates that the Win32 error code corresponds to the COM error code.</returns> | ||
public static bool Matches(int result, int win32ErrorCode) | ||
{ | ||
return (result == HResultFromWin32(win32ErrorCode)); | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.