コード例 #1
0
        /// <summary>
        /// Returns true if SafeFileHandle subclass value has changed else returns false
        /// </summary>
        /// <returns></returns>
        public static bool IsChanged(ChildSafeFileHandle hnd)
        {
            Int32 hndInt32 = SHInt32(hnd); //get the 32-bit value associated with hnd

            if (hndInt32 == ReturnValue)
            {
                return(true);
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Creates and returns a new ChildSafeFileHandle
        /// </summary>
        /// <returns></returns>
        public static ChildSafeFileHandle NewChildSFH()
        {
            String              lpFileName            = "B.txt";
            DesiredAccess       dwDesiredAccess       = DesiredAccess.GENERIC_WRITE;
            ShareMode           dwShareMode           = ShareMode.FILE_SHARE_WRITE;
            IntPtr              lpSecurityAttributes  = IntPtr.Zero;
            CreationDisposition dwCreationDisposition = CreationDisposition.CREATE_ALWAYS;
            FlagsAndAttributes  dwFlagsAndAttributes  = FlagsAndAttributes.None;
            IntPtr              hTemplateFile         = IntPtr.Zero;

            //create the handle
            ChildSafeFileHandle hnd = ChildSafeFileHandle.CreateChildSafeFileHandle(lpFileName, dwDesiredAccess, dwShareMode,
                                                                                    lpSecurityAttributes, dwCreationDisposition,
                                                                                    dwFlagsAndAttributes, hTemplateFile);

            return(hnd);
        }
コード例 #3
0
        /// <summary>
        /// Returns the Int32 value associated with a ChildSafeFileHandle
        /// </summary>
        /// <returns></returns>
        public static Int32 SHInt32(ChildSafeFileHandle hnd)
        {
            IntPtr hndIntPtr = hnd.DangerousGetHandle(); //get the IntPtr associated with hnd

            return(hndIntPtr.ToInt32());                 //return the 32-bit value associated with hnd
        }