本文整理汇总了C#中System.Runtime.InteropServices.COMException类的典型用法代码示例。如果您正苦于以下问题:C# COMException类的具体用法?C# COMException怎么用?C# COMException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
COMException类属于System.Runtime.InteropServices命名空间,在下文中一共展示了COMException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateClass
static public IntPtr CreateClass(Guid rclsid, Guid riid)
{
IntPtr classFactory;
IntPtr objCreatedObject;
COMException Exception;
// Create a local copy so that we can pass it's reference
Guid IClassFactory = IID_IClassFactory;
int hr;
hr = DllGetClassObject(ref rclsid, ref IClassFactory, out classFactory);
try
{
if (hr < 0)
{
Exception = new COMException("Call to DllGetClassObject failed.", hr);
throw Exception;
}
hr = ClassFactory_CreateInstance(classFactory, ref riid, out objCreatedObject);
if (hr < 0)
{
Exception = new COMException("Call to CreateInstance failed.", hr);
throw Exception;
}
}
finally
{
ClassFactory_Release(classFactory);
}
return objCreatedObject;
}
开发者ID:ArildF,项目名称:masters,代码行数:31,代码来源:isymwrapper.cs
示例2: GetErrorMessage
public static string GetErrorMessage(COMException ce)
{
//These error messages come from the WIA documenation.
if (ce.ErrorCode == WIA_ERROR_GENERAL_ERROR) { return "An unknown error has occurred with the Windows Image Acquisition (WIA) device."; }
if (ce.ErrorCode == WIA_ERROR_PAPER_JAM) { return "Paper is jammed in the scanner's document feeder."; }
if (ce.ErrorCode == WIA_ERROR_PAPER_EMPTY) { return "The user requested a scan and there are no documents left in the document feeder."; }
if (ce.ErrorCode == WIA_ERROR_PAPER_PROBLEM) { return "An unspecified problem occurred with the scanner's document feeder."; }
if (ce.ErrorCode == WIA_ERROR_OFFLINE) { return "The WIA device is not online."; }
if (ce.ErrorCode == WIA_ERROR_BUSY) { return "The WIA device is busy."; }
if (ce.ErrorCode == WIA_ERROR_WARMING_UP) { return "The WIA device is warming up."; }
if (ce.ErrorCode == WIA_ERROR_USER_INTERVENTION) { return "An unspecified error has occurred with the WIA device that requires user intervention. The user should ensure that the device is turned on, online, and any cables are properly connected."; }
if (ce.ErrorCode == WIA_ERROR_ITEM_DELETED) { return "The WIA device was deleted. It can no longer be accessed."; }
if (ce.ErrorCode == WIA_ERROR_DEVICE_COMMUNICATION) { return " An unspecified error occurred during an attempted communication with the WIA device."; }
if (ce.ErrorCode == WIA_ERROR_INVALID_COMMAND) { return " The device does not support this command."; }
if (ce.ErrorCode == WIA_ERROR_INCORRECT_HARDWARE_SETTING) { return "There is an incorrect setting on the WIA device."; }
if (ce.ErrorCode == WIA_ERROR_DEVICE_LOCKED) { return "The scanner head is locked."; }
if (ce.ErrorCode == WIA_ERROR_EXCEPTION_IN_DRIVER) { return "The device driver threw an exception."; }
if (ce.ErrorCode == WIA_ERROR_INVALID_DRIVER_RESPONSE) { return "The response from the driver is invalid."; }
if (ce.ErrorCode == WIA_S_NO_DEVICE_AVAILABLE) { return "No WIA device of the selected type is available."; }
//These error messages are totally made up because they don't appear in the
//documentation but are defined in WiaDef.h
if (ce.ErrorCode == WIA_ERROR_COVER_OPEN) { return "The device cover is open."; }
if (ce.ErrorCode == WIA_ERROR_LAMP_OFF) { return "The devices lamp is off."; }
if (ce.ErrorCode == WIA_ERROR_DESTINATION) { return "The destination is invalid"; }
if (ce.ErrorCode == WIA_ERROR_NETWORK_RESERVATION_FAILED) { return "A network error occurred."; }
if (ce.ErrorCode == WIA_STATUS_END_OF_MEDIA) { return "End of media reached."; }
//Watch for the specific error that means that the Wia Automation library is not installed.
if (ce.ErrorCode == COM_ERROR_CLASS_NOT_REGISTERED) { return ce.Message + "\r\nEnsure that the WIA Automation Library 2.0 is installed and registered."; }
//If it's not a WIA error then just return the message we got from COM.
return ce.Message;
}
开发者ID:flashcurd,项目名称:WiaInterop,代码行数:34,代码来源:WiaError.cs
示例3: HttpException
public HttpException(HttpResponseMessage response, COMException innerException, string message = null)
: this(GetResponseExceptionMessage(response, message), innerException)
{
HResult = innerException.HResult;
_request = response?.RequestMessage;
_response = response;
}
开发者ID:ali-hk,项目名称:Toolkit,代码行数:7,代码来源:HttpException.cs
示例4: ConvertException
private static bool ConvertException(COMException e, out Exception uiaException)
{
bool handled = true;
switch (e.ErrorCode)
{
case UIA_E_ELEMENTNOTAVAILABLE:
uiaException = new ElementNotAvailableException(e);
break;
case UIA_E_ELEMENTNOTENABLED:
uiaException = new ElementNotEnabledException(e);
break;
case UIA_E_NOCLICKABLEPOINT:
uiaException = new NoClickablePointException(e);
break;
case UIA_E_PROXYASSEMBLYNOTLOADED:
uiaException = new ProxyAssemblyNotLoadedException(e);
break;
default:
uiaException = null;
handled = false;
break;
}
return handled;
}
开发者ID:TestStack,项目名称:uia-custom-pattern-managed,代码行数:28,代码来源:NativeMethods.cs
示例5: ReportCOMError
// Helper funciton.
static void ReportCOMError(COMException e)
{
Console.WriteLine("*************************************");
Console.WriteLine("Raw HRESULT: {0}", e.ErrorCode);
Console.WriteLine("Message: {0}", e.Message);
Console.WriteLine("Source of error: {0}", e.Source);
Console.WriteLine("Method Name: {0}", e.TargetSite);
Console.WriteLine("*************************************\n");
}
开发者ID:rojac07,项目名称:COM,代码行数:10,代码来源:ComErrorClient.cs
示例6: UPnPException
/// <summary>
/// Creates a new UPnPException.
/// </summary>
/// <param name="comException">The underlying COM Exception.</param>
public UPnPException(COMException comException)
: base(String.Format(
"UPnP Error #{0}: {1}",
comException.ErrorCode,
((UPnPErrorCode)(comException.ErrorCode)).ToString()),
comException)
{
mecCode = (UPnPErrorCode)(comException.ErrorCode);
}
开发者ID:jogibear9988,项目名称:ManagedUPnP,代码行数:13,代码来源:UPnPException.cs
示例7: SDKConnectionException
public SDKConnectionException(COMException cex)
: base(cex)
{
switch ((uint)cex.ErrorCode)
{
default:
ProblemDetail = String.Format("{0}, Code: {1:X}", cex.Message, cex.ErrorCode);
break;
}
}
开发者ID:pkpjpm,项目名称:Zombie,代码行数:10,代码来源:SDKExceptions.cs
示例8: CreateFormattedComException
internal static Exception CreateFormattedComException(COMException e)
{
StringBuilder errorBuffer = new StringBuilder(0x100);
StringBuilder nameBuffer = new StringBuilder();
int error = 0;
SafeNativeMethods.ADsGetLastError(out error, errorBuffer, 0x100, nameBuffer, 0);
if (error != 0)
{
return new DirectoryServicesCOMException(errorBuffer.ToString(), error, e);
}
return e;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:12,代码来源:COMExceptionHelper.cs
示例9: CreateFormattedComException
internal static Exception CreateFormattedComException(COMException e)
{
// get extended error information
StringBuilder errorBuffer = new StringBuilder(256);
StringBuilder nameBuffer = new StringBuilder();
int error = 0;
SafeNativeMethods.ADsGetLastError(out error, errorBuffer, 256, nameBuffer, 0);
if (error != 0)
return new DirectoryServicesCOMException(errorBuffer.ToString(), error, e);
else
return e;
}
开发者ID:chcosta,项目名称:corefx,代码行数:13,代码来源:DirectoryServicesCOMException.cs
示例10: ThrowExceptionForHR
public static void ThrowExceptionForHR(int hr)
{
if (hr < 0)
{
string s = GetErrorText(hr);
COMException ex = null;
if (string.IsNullOrEmpty(s))
ex = new COMException("COM Error", hr);
else
ex = new COMException(s, hr);
throw ex;
}
}
开发者ID:rraguso,项目名称:protone-suite,代码行数:15,代码来源:DShowTypes.cs
示例11: GetException
internal Exception GetException()
{
Debug.Assert(_pfnDeferredFillIn == IntPtr.Zero);
#if DEBUG
System.Diagnostics.Debug.Assert(_wReserved != -1);
_wReserved = -1; // to ensure that the method gets called only once
#endif
int errorCode = (_scode != 0) ? _scode : _wCode;
Exception exception = Marshal.GetExceptionForHR(errorCode);
string message = ConvertAndFreeBstr(ref _bstrDescription);
if (message != null)
{
// If we have a custom message, create a new Exception object with the message set correctly.
// We need to create a new object because "exception.Message" is a read-only property.
if (exception is COMException)
{
exception = new COMException(message, errorCode);
}
else
{
Type exceptionType = exception.GetType();
ConstructorInfo ctor = exceptionType.GetConstructor(new Type[] { typeof(string) });
if (ctor != null)
{
exception = (Exception)ctor.Invoke(new object[] { message });
}
}
}
exception.Source = ConvertAndFreeBstr(ref _bstrSource);
string helpLink = ConvertAndFreeBstr(ref _bstrHelpFile);
if (helpLink != null && _dwHelpContext != 0)
{
helpLink += "#" + _dwHelpContext;
}
exception.HelpLink = helpLink;
return exception;
}
开发者ID:40a,项目名称:PowerShell,代码行数:42,代码来源:ExcepInfo.cs
示例12: SDKSessionException
public SDKSessionException(COMException cex)
: base(cex)
{
switch ((uint)cex.ErrorCode)
{
//Possible enhancements: Handle connection failure for online edition
//also we need to support the case where a company file has been specified
//perhaps a special callback for customizing this message?
case 0x80040408: //old school: could not start QuickBooks
case 0x80040416: //specify co file if not running
case 0x80040417: //specify co file if no file open
ProblemDetail = "Can't connect to QuickBooks. Please make sure:"
+ Environment.NewLine + "1. QuickBooks is running"
+ Environment.NewLine + "2. If QuickBooks is running, check for an application authorization dialog"
+ Environment.NewLine + "3. If using Vista or Windows 7, make sure UAC is enabled";
break;
default:
//it's only necessary to override the default message if we have something to say
ProblemDetail = String.Format("{0}, Code: {1:X}", cex.Message, cex.ErrorCode);
break;
}
}
开发者ID:pkpjpm,项目名称:Zombie,代码行数:23,代码来源:SDKExceptions.cs
示例13: GetMappingExceptionForHR
/// <summary>
/// This does a mapping from hr to the exception and also takes care of making default exception in case of classic COM as COMException.
/// and in winrt and marshal APIs as Exception.
/// </summary>
/// <param name="errorCode"></param>
/// <param name="message"></param>
/// <param name="createCOMException"></param>
/// <returns></returns>
internal static Exception GetMappingExceptionForHR(int errorCode, string message, bool createCOMException, bool hasErrorInfo)
{
if (errorCode >= 0)
{
return null;
}
Exception exception = null;
bool shouldDisplayHR = false;
switch (errorCode)
{
case __HResults.COR_E_NOTFINITENUMBER: // NotFiniteNumberException
case __HResults.COR_E_ARITHMETIC:
exception = new ArithmeticException();
break;
case __HResults.COR_E_ARGUMENT:
case unchecked((int)0x800A01C1):
case unchecked((int)0x800A01C2):
case __HResults.CLR_E_BIND_UNRECOGNIZED_IDENTITY_FORMAT:
exception = new ArgumentException();
if (errorCode != __HResults.COR_E_ARGUMENT)
shouldDisplayHR = true;
break;
case __HResults.E_BOUNDS:
case __HResults.COR_E_ARGUMENTOUTOFRANGE:
case __HResults.ERROR_NO_UNICODE_TRANSLATION:
exception = new ArgumentOutOfRangeException();
if (errorCode != __HResults.COR_E_ARGUMENTOUTOFRANGE)
shouldDisplayHR = true;
break;
case __HResults.COR_E_ARRAYTYPEMISMATCH:
exception = new ArrayTypeMismatchException();
break;
case __HResults.COR_E_BADIMAGEFORMAT:
case __HResults.CLDB_E_FILE_OLDVER:
case __HResults.CLDB_E_INDEX_NOTFOUND:
case __HResults.CLDB_E_FILE_CORRUPT:
case __HResults.COR_E_NEWER_RUNTIME:
case __HResults.COR_E_ASSEMBLYEXPECTED:
case __HResults.ERROR_BAD_EXE_FORMAT:
case __HResults.ERROR_EXE_MARKED_INVALID:
case __HResults.CORSEC_E_INVALID_IMAGE_FORMAT:
case __HResults.ERROR_NOACCESS:
case __HResults.ERROR_INVALID_ORDINAL:
case __HResults.ERROR_INVALID_DLL:
case __HResults.ERROR_FILE_CORRUPT:
case __HResults.COR_E_LOADING_REFERENCE_ASSEMBLY:
case __HResults.META_E_BAD_SIGNATURE:
exception = new BadImageFormatException();
// Always show HR for BadImageFormatException
shouldDisplayHR = true;
break;
case __HResults.COR_E_CUSTOMATTRIBUTEFORMAT:
exception = new FormatException();
break; // CustomAttributeFormatException
case __HResults.COR_E_DATAMISALIGNED:
exception = InteropExtensions.CreateDataMisalignedException(message); // TODO: Do we need to add msg here?
break;
case __HResults.COR_E_DIVIDEBYZERO:
case __HResults.CTL_E_DIVISIONBYZERO:
exception = new DivideByZeroException();
if (errorCode != __HResults.COR_E_DIVIDEBYZERO)
shouldDisplayHR = true;
break;
case __HResults.COR_E_DLLNOTFOUND:
#if ENABLE_WINRT
exception = new DllNotFoundException();
#endif
break;
case __HResults.COR_E_DUPLICATEWAITOBJECT:
exception = new ArgumentException();
break; // DuplicateWaitObjectException
case __HResults.COR_E_ENDOFSTREAM:
case unchecked((int)0x800A003E):
exception = new System.IO.EndOfStreamException();
if (errorCode != __HResults.COR_E_ENDOFSTREAM)
shouldDisplayHR = true;
break;
case __HResults.COR_E_TYPEACCESS: // TypeAccessException
case __HResults.COR_E_ENTRYPOINTNOTFOUND:
//.........这里部分代码省略.........
开发者ID:justinvp,项目名称:corert,代码行数:101,代码来源:ExceptionHelpers.cs
示例14: StorageInvalidOperationException
public StorageInvalidOperationException(COMException innerException)
: base(message, innerException)
{
// Debug.Fail("Invalid Operation using Storage: " + innerException.Message);
}
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:5,代码来源:StorageException.cs
示例15: StorageNotCurrentException
public StorageNotCurrentException(COMException innerException)
: base(message, innerException)
{ }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:3,代码来源:StorageException.cs
示例16: StorageLockViolationException
public StorageLockViolationException(COMException innerException)
: base(message, innerException)
{ }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:3,代码来源:StorageException.cs
示例17: StorageAccessDeniedException
public StorageAccessDeniedException(COMException innerException)
: base(message, innerException)
{ }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:3,代码来源:StorageException.cs
示例18: StorageInvalidFormatException
public StorageInvalidFormatException(COMException innerException)
: base(message, innerException)
{ }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:3,代码来源:StorageException.cs
示例19: IsContextNotAvailable
private static bool IsContextNotAvailable(COMException cex)
{
unchecked
{
return cex.ErrorCode == (int)0x89711006;
}
}
开发者ID:asthomas,项目名称:Fayde,代码行数:7,代码来源:VisualStudioInstance.cs
示例20: ThrowIfFailed
public void ThrowIfFailed(string message)
{
if (Failed)
{
if (string.IsNullOrEmpty(message))
{
message = ToString();
}
#if DEBUG
else
{
message += " (" + ToString() + ")";
}
#endif
// Wow. Reflection in a throw call. Later on this may turn out to have been a bad idea.
// If you're throwing an exception I assume it's OK for me to take some time to give it back.
// I want to convert the HRESULT to a more appropriate exception type than COMException.
// Marshal.ThrowExceptionForHR does this for me, but the general call uses GetErrorInfo
// if it's set, and then ignores the HRESULT that I've provided. This makes it so this
// call works the first time but you get burned on the second. To avoid this, I use
// the overload that explicitly ignores the IErrorInfo.
// In addition, the function doesn't allow me to set the Message unless I go through
// the process of implementing an IErrorInfo and then use that. There's no stock
// implementations of IErrorInfo available and I don't think it's worth the maintenance
// overhead of doing it, nor would it have significant value over this approach.
Exception e = Marshal.GetExceptionForHR((int)_value, new IntPtr(-1));
Assert.IsNotNull(e);
// ArgumentNullException doesn't have the right constructor parameters,
// (nor does Win32Exception...)
// but E_POINTER gets mapped to NullReferenceException,
// so I don't think it will ever matter.
Assert.IsFalse(e is ArgumentNullException);
// If we're not getting anything better than a COMException from Marshal,
// then at least check the facility and attempt to do better ourselves.
if (e.GetType() == typeof(COMException))
{
switch (Facility)
{
case Facility.Win32:
e = new Win32Exception(Code, message);
break;
default:
e = new COMException(message, (int)_value);
break;
}
}
else
{
ConstructorInfo cons = e.GetType().GetConstructor(new[] { typeof(string) });
if (null != cons)
{
e = cons.Invoke(new object[] { message }) as Exception;
Assert.IsNotNull(e);
}
}
throw e;
}
}
开发者ID:alexcmd,项目名称:CascadeTrainingTool,代码行数:59,代码来源:ErrorCodes.cs
注:本文中的System.Runtime.InteropServices.COMException类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论