當前位置: 首頁>>代碼示例>>C#>>正文


C# InteropServices.COMException類代碼示例

本文整理匯總了C#中System.Runtime.InteropServices.COMException的典型用法代碼示例。如果您正苦於以下問題:C# COMException類的具體用法?C# COMException怎麽用?C# COMException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


COMException類屬於System.Runtime.InteropServices命名空間,在下文中一共展示了COMException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的System.Runtime.InteropServices.COMException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。