Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. .NET-BroadcastEventWindow - No Disk

.NET-BroadcastEventWindow - No Disk

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpcsharpdebuggingannouncementlearning
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gmarian
    wrote on last edited by
    #1

    I'm writing a Windows Explorer-like clone for myself, and I'm running into a problem with empty disk drives. When I run the application, by building the project, it works as expected. However, if I run the executable directly, I get an error window titled: ".NET-BroacastEventWindow.1.0.3300.0.1: ExplorerPlus.exe - No Disk." Normally, this error references drive A:. (Which, of course, is empty.) However, I wrap the appropriate calls in try...catch blocks. In fact, if I remove the try...catch blocks, this error will pop-up before .NET displays its message about the un-caught exception. This happens for both debug and release versions of the executable. Running the executable directly results in these errors whenever the application accesses an empty drive. However, when the executable runs as a result of the project being built, it runs just fine.

    L 1 Reply Last reply
    0
    • G gmarian

      I'm writing a Windows Explorer-like clone for myself, and I'm running into a problem with empty disk drives. When I run the application, by building the project, it works as expected. However, if I run the executable directly, I get an error window titled: ".NET-BroacastEventWindow.1.0.3300.0.1: ExplorerPlus.exe - No Disk." Normally, this error references drive A:. (Which, of course, is empty.) However, I wrap the appropriate calls in try...catch blocks. In fact, if I remove the try...catch blocks, this error will pop-up before .NET displays its message about the un-caught exception. This happens for both debug and release versions of the executable. Running the executable directly results in these errors whenever the application accesses an empty drive. However, when the executable runs as a result of the project being built, it runs just fine.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, in my Explorer replacement, I used the native function SetErrorMode to avoid the low-level error reporting taht occurs by default on empty drives. It works on all .NET versions (tested on XP only). This is part of my code:

      // avoid dialog boxes with "There is no disk in the drive" !
      using (new LP\_SetErrorMode(ErrorModes.FailCriticalErrors)) {
      	// do whatever needs to be done
      	// when leaving the using block, the ErrorMode is returned
      	// to its original value automatically
      }
      

      using System;
      using System.Runtime.InteropServices; // DllImport, MarschalAs

      namespace LP_Core {
      /// /// Possible mode flags for LP_SetErrorMode constructor.
      ///
      [Flags]
      public enum ErrorModes {
      /// /// Use the system default, which is to display all error dialog boxes
      ///
      Default=0x0,
      /// /// The system does not display the critical-error-handler message box.
      /// Instead, the system sends the error to the calling process.
      ///
      FailCriticalErrors=0x1,
      /// /// 64-bit Windows: The system automatically fixes memory alignment faults
      /// and makes them invisible to the application. It does this for the
      /// calling process and any descendant processes.
      ///
      NoOpFaultErrorBox=0x2,
      /// /// The system does not display the general-protection-fault message box.
      /// This flag should only be set by debugging applications that handle
      /// general protection (GP) faults themselves with an exception handler.
      ///
      NoAlignmentFaultExcept=0x4,
      /// /// The system does not display a message box when it fails to find a file.
      /// Instead, the error is returned to the calling process.
      ///
      NoOpenFileErrorBox=0x8000
      }
      /// /// LP_SetErrorMode temporarily changes the Windows error mode.
      /// It can be used to try and get a file list on removable media drives
      /// (in order to avoid the dialog box "There is no disk in the drive")
      ///
      public struct LP_SetErrorMode : IDisposable {
      private int oldErrorMode;

      	/// /// Create an instance of LP\_SetErrorMode to change the Windows error mode.
      	/// 
      	/// With a using statement, the original value will be restored when the
      	/// instance is automatically disposed.
      	/// 
      	public LP\_SetErrorMode(ErrorModes mode) {
      		oldErrorMode=SetErrorMode((int)mode);	//
      
      G 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, in my Explorer replacement, I used the native function SetErrorMode to avoid the low-level error reporting taht occurs by default on empty drives. It works on all .NET versions (tested on XP only). This is part of my code:

        // avoid dialog boxes with "There is no disk in the drive" !
        using (new LP\_SetErrorMode(ErrorModes.FailCriticalErrors)) {
        	// do whatever needs to be done
        	// when leaving the using block, the ErrorMode is returned
        	// to its original value automatically
        }
        

        using System;
        using System.Runtime.InteropServices; // DllImport, MarschalAs

        namespace LP_Core {
        /// /// Possible mode flags for LP_SetErrorMode constructor.
        ///
        [Flags]
        public enum ErrorModes {
        /// /// Use the system default, which is to display all error dialog boxes
        ///
        Default=0x0,
        /// /// The system does not display the critical-error-handler message box.
        /// Instead, the system sends the error to the calling process.
        ///
        FailCriticalErrors=0x1,
        /// /// 64-bit Windows: The system automatically fixes memory alignment faults
        /// and makes them invisible to the application. It does this for the
        /// calling process and any descendant processes.
        ///
        NoOpFaultErrorBox=0x2,
        /// /// The system does not display the general-protection-fault message box.
        /// This flag should only be set by debugging applications that handle
        /// general protection (GP) faults themselves with an exception handler.
        ///
        NoAlignmentFaultExcept=0x4,
        /// /// The system does not display a message box when it fails to find a file.
        /// Instead, the error is returned to the calling process.
        ///
        NoOpenFileErrorBox=0x8000
        }
        /// /// LP_SetErrorMode temporarily changes the Windows error mode.
        /// It can be used to try and get a file list on removable media drives
        /// (in order to avoid the dialog box "There is no disk in the drive")
        ///
        public struct LP_SetErrorMode : IDisposable {
        private int oldErrorMode;

        	/// /// Create an instance of LP\_SetErrorMode to change the Windows error mode.
        	/// 
        	/// With a using statement, the original value will be restored when the
        	/// instance is automatically disposed.
        	/// 
        	public LP\_SetErrorMode(ErrorModes mode) {
        		oldErrorMode=SetErrorMode((int)mode);	//
        
        G Offline
        G Offline
        gmarian
        wrote on last edited by
        #3

        Very ingenious, thank you. It works perfectly.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups