ZForge.Win32.RemovableDriveDetector.RegisterForDeviceChange C# (CSharp) Méthode

RegisterForDeviceChange() private méthode

New version which gets the handle automatically for specified directory Only for registering! Unregister with the old version of this function...
private RegisterForDeviceChange ( string dirPath ) : void
dirPath string e.g. C:\\dir
Résultat void
        private void RegisterForDeviceChange(string dirPath)
        {
            IntPtr handle = Native.OpenDirectory(dirPath);
            if (handle == IntPtr.Zero)
            {
                mDeviceNotifyHandle = IntPtr.Zero;
                return;
            }
            else
                mDirHandle = handle;    // save handle for closing it when unregistering

            // Register for handle
            DEV_BROADCAST_HANDLE data = new DEV_BROADCAST_HANDLE();
            data.dbch_devicetype = DBT_DEVTYP_HANDLE;
            data.dbch_reserved = 0;
            data.dbch_nameoffset = 0;
            //data.dbch_data = null;
            //data.dbch_eventguid = 0;
            data.dbch_handle = handle;
            data.dbch_hdevnotify = (IntPtr)0;
            int size = Marshal.SizeOf(data);
            data.dbch_size = size;
            IntPtr buffer = Marshal.AllocHGlobal(size);
            Marshal.StructureToPtr(data, buffer, true);

            mDeviceNotifyHandle = Native.RegisterDeviceNotification(mRecipientHandle, buffer, 0);
        }

Same methods

RemovableDriveDetector::RegisterForDeviceChange ( bool register, SafeFileHandle fileHandle ) : void