Beispiel #1
0
        public unsafe int OnDeviceEvent(int eventType, WIN32.DEV_BROADCAST_HDR* pHeader)
        {
            int result = WIN32.NO_ERROR;
            bool cancel = false;

            // https://msdn.microsoft.com/en-us/library/windows/desktop/aa363205(v=vs.85).aspx

            switch (eventType)
                {
            // pHeader is non-NULL
            case WIN32.DBT_DEVICEARRIVAL:
                TraceEvent("device arrived: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceArrived, pHeader);
                break;
            case WIN32.DBT_DEVICEQUERYREMOVE:
                TraceEvent("query device remove: {0}", pHeader->DeviceTypeName);
                cancel = RaiseDeviceEvent(DeviceQueryRemove, pHeader);
                result = cancel ? WIN32.BROADCAST_QUERY_DENY : WIN32.TRUE;
                break;
            case WIN32.DBT_DEVICEQUERYREMOVEFAILED:
                TraceEvent("query device remove failed: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceQueryRemoveFailed, pHeader);
                break;
            case WIN32.DBT_DEVICEREMOVEPENDING:
                TraceEvent("device remove pending: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceRemovePending, pHeader);
                break;
            case WIN32.DBT_DEVICEREMOVECOMPLETE:
                TraceEvent("device remove complete: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceRemoveComplete, pHeader);
                break;

            case WIN32.DBT_DEVICETYPESPECIFIC:
                TraceEvent("device type specific: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceTypeSpecific, pHeader);
                break;
            case WIN32.DBT_CUSTOMEVENT:
                TraceEvent("device custom: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceCustomEvent, pHeader);
                break;
            case WIN32.DBT_USERDEFINED:
                TraceEvent("device user defined: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceUserDefined, pHeader);
                break;

            // pHeader is NULL
            case WIN32.DBT_QUERYCHANGECONFIG:
                TraceEvent("device query change config: {0}", pHeader->DeviceTypeName);
                cancel = RaiseDeviceEvent(DeviceQueryChangeConfig);
                result = cancel ? WIN32.BROADCAST_QUERY_DENY : WIN32.TRUE;
                break;
            case WIN32.DBT_CONFIGCHANGED:
                TraceEvent("device config changed: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceConfigChanged);
                break;
            case WIN32.DBT_CONFIGCHANGECANCELED:
                TraceEvent("device config change cancelled: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceConfigChangeCancelled);
                break;
            case WIN32.DBT_DEVNODES_CHANGED:
                TraceEvent("device devnodes changed: {0}", pHeader->DeviceTypeName);
                RaiseDeviceEvent(DeviceDevNodesChanged);
                break;

            default:
                TraceEvent("unknown device event: {0}", eventType);
                break;
                }

            return result;
        }
Beispiel #2
0
 private unsafe bool RaiseDeviceEvent(EventHandler<DeviceEventArgsCancel> evt, WIN32.DEV_BROADCAST_HDR* pHeader)
 {
     if (evt != null)
         {
         DeviceEventArgsCancel args = new DeviceEventArgsCancel();
         args.pHeader = pHeader;
         args.Cancel  = false;
         evt(null, args);
         return args.Cancel;
         }
     return false;
 }
Beispiel #3
0
 public unsafe bool ShouldDeferDeviceEvent(int eventType, WIN32.DEV_BROADCAST_HDR* pHeader)
 {
     // We basically can't defer any of these events, as the data pointed
     // to by pHeader will be invalid by the time we return, and so will be
     // junk in a deferred invocation.
     return false;
 }
Beispiel #4
0
 private unsafe void RaiseDeviceEvent(EventHandler<DeviceEventArgs> evt, WIN32.DEV_BROADCAST_HDR* pHeader)
 {
     if (evt != null)
         {
         DeviceEventArgs args = new DeviceEventArgs();
         args.pHeader = pHeader;
         evt(null, args);
         }
 }
Beispiel #5
0
 void WIN32.IOleClientSite.GetContainer(out WIN32.IOleContainer ppContainer)
 {
     throw new NotImplementedException();
 }