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


C# ComponentModel.Win32Exception類代碼示例

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


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

示例1: UnmapFolderFromDrive

		// --------------------------------------------------------------------------- ------------- 
		// Class Name:  VolumeFunctions 
		// Procedure Name: UnmapFolderFromDrive 
		// Purpose:   Unmap a drive letter. We always unmp the drive, without checking the 
		//                  folder name. 
		// Parameters: 
		//  - driveLetter (string)  :   Drive letter to be released, the the format "C:" 
		//  - folderName (string)  :    Folder name that the drive is mapped to. 
		// --------------------------------------------------------------------------- ------------- 
		internal static string UnmapFolderFromDrive(string driveLetter, string folderName)
		{
			DefineDosDevice(DDD_REMOVE_DEFINITION, driveLetter, folderName);
			// Display the status of the "last" unmap we run. 
			string statusMessage = new Win32Exception(Marshal.GetLastWin32Error()).ToString();
			return statusMessage.Substring(statusMessage.IndexOf(":") + 1);
		}
開發者ID:exaphaser,項目名稱:JSC-Cross-Compiler,代碼行數:16,代碼來源:VolumeFunctionsProvider.cs

示例2: ThrowCanNotLoadDll

        static void ThrowCanNotLoadDll(string dllPath, int error)
        {
            var type = WinAPI.GetDllMachineType(dllPath);
            if (type == MachineType.IMAGE_FILE_MACHINE_I386)
            {
                if (sizeof(long) == IntPtr.Size)
                {
                    var message = string.Format("x64 process tries to load x86 dll = {0}; code = 0x{1:X}", dllPath, error);
                    throw new Exception(message);
                }
            }
            else if (type == MachineType.IMAGE_FILE_MACHINE_AMD64)
            {
                if (sizeof(int) == IntPtr.Size)
                {
                    var message = string.Format("x86 process tries to load x64 dll = {0}; code = 0x{1:X}", dllPath, error);
                    throw new Exception(message);
                }
            }
            else
            {
                var message = string.Format("Unsupported machine type = {0} of dll = {1}; error = 0x{2:X}.", type, dllPath, error);
                throw new Exception(message);
            }

            {
                var ex = new Win32Exception(error);
                var message = string.Format("Can not load library = {0} Code={1}", dllPath, error);
                throw new Exception(message, ex);
            }
        }
開發者ID:ifzz,項目名稱:FDK,代碼行數:31,代碼來源:InProcessHost.cs

示例3: ChangeOwner

        public static void ChangeOwner(String s_Path, String s_UserName)
        {
            IntPtr pNewOwner, peUse;
            Win32Exception Win32Error;
            String domain_name;
            int ret, sid_len, domain_len;

            if (Privileges.SetPrivileges() == false)
                throw new Exception("Required privilege not held by the user");

            sid_len = SID_SIZE;
            pNewOwner = Marshal.AllocHGlobal(sid_len);
            domain_len = NAME_SIZE;
            domain_name = String.Empty.PadLeft(domain_len);
            peUse = IntPtr.Zero;

            if (!Imports.LookupAccountName(null, s_UserName, pNewOwner, ref sid_len, domain_name, ref domain_len, ref peUse))
            {
                ret = Marshal.GetLastWin32Error();
                Win32Error = new Win32Exception(ret);
                throw new Exception(Win32Error.Message);
            }
            ret = Imports.SetNamedSecurityInfo(s_Path, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION, pNewOwner, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
            if (ret != 0)
            {
                Win32Error = new Win32Exception(ret);
                throw new Exception(Win32Error.Message);
            }
            Marshal.FreeHGlobal(pNewOwner);
        }
開發者ID:galaxy001,項目名稱:WindSLIC,代碼行數:30,代碼來源:Owner.cs

示例4: InstantiateException

        public static void InstantiateException()
        {
            int error = 5;
            string message = "This is an error message.";
            Exception innerException = new FormatException();

            // Test each of the constructors and validate the properties of the resulting instance

            Win32Exception ex = new Win32Exception();
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);

            ex = new Win32Exception(error);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: error, actual: ex.NativeErrorCode);

            ex = new Win32Exception(message);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: message, actual: ex.Message);

            ex = new Win32Exception(error, message);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: error, actual: ex.NativeErrorCode);
            Assert.Equal(expected: message, actual: ex.Message);

            ex = new Win32Exception(message, innerException);
            Assert.Equal(expected: E_FAIL, actual: ex.HResult);
            Assert.Equal(expected: message, actual: ex.Message);
            Assert.Same(expected: innerException, actual: ex.InnerException);
        }
開發者ID:Rayislandstyle,項目名稱:corefx,代碼行數:29,代碼來源:Win32Exception.cs

示例5: DebugHelper

        public DebugHelper(string exeName)
        {
            IntPtr handle = Process.GetCurrentProcess().Handle;
            NativeMethods.SetErrorMode(NativeMethods.SetErrorFlags.SEM_FAILCRITICALERRORS | NativeMethods.SetErrorFlags.SEM_NOOPENFILEERRORBOX);

            NativeMethods.SymSetOptions(NativeMethods.Options.SYMOPT_DEFERRED_LOADS | NativeMethods.Options.SYMOPT_DEBUG);

            if (!NativeMethods.SymInitialize(handle, null, false))
            {
                var ex = new Win32Exception(Marshal.GetLastWin32Error());
                LastErrorMessage = ex.Message;
            }

            _dllBase = NativeMethods.SymLoadModuleEx(handle,
                IntPtr.Zero,
                exeName,
                null,
                0,
                0,
                IntPtr.Zero,
                NativeMethods.SymLoadModuleFlags.SLMFLAG_NONE);
            if (_dllBase == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            _libHandle = handle;
        }
開發者ID:jwk000,項目名稱:vs-boost-unit-test-adapter,代碼行數:27,代碼來源:DebugHelperNative.cs

示例6: ctor

		[Test] // ctor (int)
		public void Constructor1 ()
		{
			Win32Exception ex;

			ex = new Win32Exception (0);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#A1");
			Assert.IsNull (ex.InnerException, "#A2");
			Assert.IsNotNull (ex.Message, "#A3");
			Assert.IsFalse (ex.Message.IndexOf (ex.GetType ().FullName) != -1, "#A4");
			Assert.AreEqual (0, ex.NativeErrorCode, "#A5");

			ex = new Win32Exception (int.MinValue);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#B1");
			Assert.IsNull (ex.InnerException, "#B2");
			Assert.IsNotNull (ex.Message, "#B3");
			Assert.IsFalse (ex.Message.IndexOf (ex.GetType ().FullName) != -1, "#B4");
			Assert.AreEqual (int.MinValue, ex.NativeErrorCode, "#B5");

			ex = new Win32Exception (int.MaxValue);
			Assert.AreEqual (-2147467259, ex.ErrorCode, "#C1");
			Assert.IsNull (ex.InnerException, "#C2");
			Assert.IsNotNull (ex.Message, "#C3");
			Assert.IsFalse (ex.Message.IndexOf (ex.GetType ().FullName) != -1, "#C4");
			Assert.AreEqual (int.MaxValue, ex.NativeErrorCode, "#C5");
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:26,代碼來源:Win32ExceptionTest.cs

示例7: HandleCreateDirectoryExError

 /// <summary>
 /// Handles any errors that CreateDirectoryEx may encounter
 /// </summary>
 private static void HandleCreateDirectoryExError(string template, string target, int errorCode)
 {
     Win32Exception win32Exception = new Win32Exception(errorCode);
     Exception error;
     switch ((Win32Error)errorCode)
     {
         case Win32Error.ACCESS_DENIED:
             error = new UnauthorizedAccessException(
                 string.Format("Access was denied to clone '{0}' to '{1}'.", template, target),
                 win32Exception);
             break;
         case Win32Error.PATH_NOT_FOUND:
             error = new DirectoryNotFoundException(
                 string.Format("The path '{0}' or '{1}' could not be found.", template, target),
                 win32Exception);
             break;
         case Win32Error.SHARING_VIOLATION:
             error = new SharingViolationException(
                 string.Format("The source or destination file was in use when copying '{0}' to '{1}'.", template, target),
                 win32Exception);
             break;
         case Win32Error.ALREADY_EXISTS:
             //If the directory already exists don't worry about it.
             return;
         default:
             error = win32Exception;
             break;
     }
     throw error;
 }
開發者ID:joflashstudios,項目名稱:PGB,代碼行數:33,代碼來源:DirectoryCloner.cs

示例8: AquireLock

        public bool AquireLock(int timeout)
        {
            bool success = false;

            if (Monitor.TryEnter(syncRoot, timeout))
            {
                if (this.stream == null)
                {
                    int fd = Syscall.open(PortFilePath, OpenFlags.O_RDWR | OpenFlags.O_EXCL);

                    if (fd == -1)
                    {
                        var e = new Win32Exception(Marshal.GetLastWin32Error());
                        Debug.WriteLine(string.Format("Error opening {0}: {1}", PortFilePath, e.Message));

                        Monitor.Exit(syncRoot);
                    }
                    else
                    {
                        this.stream = new UnixStream(fd);
                        success = true;
                    }
                }
            }

            return success;
        }
開發者ID:binmallow,項目名稱:nbfc,代碼行數:27,代碼來源:ECLinux.cs

示例9: ExternalToolLaunchException

 public ExternalToolLaunchException(string ExecutableFilePath, string WorkingDirectoryPath, IEnumerable<ILaunchParameter> Parameters,
                                    Win32Exception inner)
     : base(string.Format("{0} ({1})", ExceptionMessage, ExecutableFilePath.Split(Path.DirectorySeparatorChar).Last()), inner)
 {
     this.ExecutableFilePath = ExecutableFilePath;
     this.WorkingDirectoryPath = WorkingDirectoryPath;
     this.Parameters = Parameters;
 }
開發者ID:NpoSaut,項目名稱:netFirmwaring,代碼行數:8,代碼來源:ExternalToolLaunchException.cs

示例10: GetExceptionForLastWin32Error

		// WinUser.h


		/// <summary>Returns an exception corresponding to the last Win32 error.</summary>
		/// <returns>Returns an exception corresponding to the last Win32 error.</returns>
		internal static Exception GetExceptionForLastWin32Error()
		{
			var errorCode = Marshal.GetLastWin32Error();
			var ex = Marshal.GetExceptionForHR( errorCode );
			if( ex == null )
				ex = new Win32Exception( errorCode );
			return ex;
		}
開發者ID:YHiniger,項目名稱:ManagedX.Input,代碼行數:13,代碼來源:RawInput.NativeMethods.cs

示例11: CloseConsole

 /// <summary>
 /// Closes the console associate to the current process
 /// </summary>
 public static void CloseConsole()
 {
     bool result = FreeConsole();
     if (!result)
     {
         Win32Exception ex = new Win32Exception(Marshal.GetLastWin32Error());
         throw new Exception(string.Format("Failed to close console: {0}", ex.Message));
     }
 }
開發者ID:Julien-Pires,項目名稱:Pulsar.Demo,代碼行數:12,代碼來源:ConsoleHelper.cs

示例12: WriteValue

 public void WriteValue(string strSection, string strKey, string strValue)
 {
     int res = WritePrivateProfileString(strSection, strKey, strValue, this.m_fileName);
     if (res == 0)
     {
         Win32Exception wexp = new Win32Exception(Marshal.GetLastWin32Error());
         throw new IniFileParsingException("win32:" + wexp.Message);
     }
 }
開發者ID:kleopatra999,項目名稱:pyxels,代碼行數:9,代碼來源:CsIniFile.cs

示例13: OnStartup

        protected override void OnStartup(StartupEventArgs e)
        {
            var test = Shcore.SetProcessDpiAwareness(PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE);
            if (!test)
            {
                var err = new Win32Exception();
            }

            base.OnStartup(e);
        }
開發者ID:soukoku,項目名稱:ModernWPF,代碼行數:10,代碼來源:App.xaml.cs

示例14: LoadDll

 /// <summary>
 /// managed wrapper around LoadLibrary
 /// </summary>
 /// <param name="dllName"></param>
 internal static void LoadDll(string dllName)
 {
     if (tempFolder == "")
     throw new Exception("Please call ExtractEmbeddedDlls before LoadDll");
       IntPtr h = LoadLibrary(dllName);
       if (h == IntPtr.Zero)
       {
     Exception e = new Win32Exception();
     throw new DllNotFoundException(String.Format("Unable to load library: {0} from {1}", dllName, tempFolder), e);
       }
 }
開發者ID:Nihlus,項目名稱:Ocucam-Arduino,代碼行數:15,代碼來源:EmbeddedDllClass.cs

示例15: Read

	public int Read(int BytesToRead)
	{
		int BytesRead = 0;
		if (!ReadFile( pHandle, pBuffer, BytesToRead, &BytesRead, 0 ))
		{
			Win32Exception WE = new Win32Exception();
			ApplicationException AE = new ApplicationException( "WinFileIO:Read - Error occurred reading a file. - " + WE.Message);
			throw AE;
		}
		return BytesRead;
	}
開發者ID:Dutchman97,項目名稱:ConcurrencyPracticum3,代碼行數:11,代碼來源:fastfile.cs


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