• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ComponentModel.Win32Exception类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.ComponentModel.Win32Exception的典型用法代码示例。如果您正苦于以下问题:C# Win32Exception类的具体用法?C# Win32Exception怎么用?C# Win32Exception使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Win32Exception类属于System.ComponentModel命名空间,在下文中一共展示了Win32Exception类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: OpenForReading

	public void OpenForReading(string FileName)
	{
		Close();
		pHandle = CreateFile( FileName, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0 );
		if (pHandle == System.IntPtr.Zero)
		{
			Win32Exception WE = new Win32Exception();
			ApplicationException AE = new ApplicationException("WinFileIO:OpenForReading - Could not open file " + FileName + " - " + WE.Message);
			throw AE;
		}
	}
开发者ID:Dutchman97,项目名称:ConcurrencyPracticum3,代码行数:11,代码来源:fastfile.cs


示例17: acceptInterrupted

 public static bool acceptInterrupted(Win32Exception ex)
 {
     if(interrupted(ex))
     {
         return true;
     }
     int error = ex.NativeErrorCode;
     return error == WSAECONNABORTED ||
            error == WSAECONNRESET ||
            error == WSAETIMEDOUT;
 }
开发者ID:bholl,项目名称:zeroc-ice,代码行数:11,代码来源:Network.cs


示例18: OpenProcessForQuery

        static SafeCloseHandle OpenProcessForQuery(int pid)
        {
#pragma warning suppress 56523 // Microsoft, Win32Exception ctor calls Marshal.GetLastWin32Error()
            SafeCloseHandle process = ListenerUnsafeNativeMethods.OpenProcess(ListenerUnsafeNativeMethods.PROCESS_QUERY_INFORMATION, false, pid);
            if (process.IsInvalid)
            {
                Exception exception = new Win32Exception();
                process.SetHandleAsInvalid();
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception);
            }
            return process;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:12,代码来源:Utility.cs


示例19: MapFolderToDrive

		// --------------------------------------------------------------------------- ------------- 
		// Class Name:  VolumeFunctions 
		// Procedure Name: MapFolderToDrive 
		// Purpose:   Map the folder to a drive letter 
		// Parameters: 
		//  - driveLetter (string)  : Drive letter in the format "C:" without a back slash 
		//  - folderName (string)  : Folder to map without a back slash 
		// --------------------------------------------------------------------------- ------------- 
		internal static string MapFolderToDrive(string driveLetter, string folderName)
		{
			// Is this drive already mapped? If so, we don't remap it! 
			StringBuilder volumeMap = new StringBuilder(1024);
			QueryDosDevice(driveLetter, volumeMap, (uint)1024);
			if (volumeMap.ToString().StartsWith(MAPPED_FOLDER_INDICATOR) == true)
				return "Volume is already mapped - map not changed";
			// Map the folder to the drive 
			DefineDosDevice(0, driveLetter, folderName);
			// Display a status message to the user. 
			string statusMessage = new Win32Exception(Marshal.GetLastWin32Error()).ToString();
			return statusMessage.Substring(statusMessage.IndexOf(":") + 1);
		}
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:21,代码来源:VolumeFunctionsProvider.cs


示例20: Reporter

      private static string Reporter(bool condensed = false)
      {
         var lastError = new Win32Exception();

         StopWatcher();

         if (condensed)
            return string.Format(CultureInfo.CurrentCulture, "{0} [{1}: {2}]", StopWatcher(), lastError.NativeErrorCode,
                                 lastError.Message);

         return string.Format(CultureInfo.CurrentCulture, "\t\t{0}\t*Win32 Result: [{1, 4}]\t*Win32 Message: [{2}]",
                              StopWatcher(), lastError.NativeErrorCode, lastError.Message);
      }
开发者ID:Sicos1977,项目名称:AlphaFS,代码行数:13,代码来源:AlphaFS_DeviceTest.cs



注:本文中的System.ComponentModel.Win32Exception类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Hosting.AssemblyCatalog类代码示例发布时间:2022-05-26
下一篇:
C# ComponentModel.TypeDescriptionProvider类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap