Exemplo n.º 1
0
        public static IntPtr Run(string fileName, DesiredAccessFlags desiredAccess, ShareModeFlags shareMode, CreationDispositionEnum creationDisposition, FlagsAndAttributes flagsAndAttributes, IntPtr templateFile)
        {
            //var buffer = IntPtr.Zero;
            var handle = IntPtr.Zero;

            var securityAttributes = new SecurityAttributes
            {
                lpSecurityDescriptor = IntPtr.Zero, //TODO: create other methods to use this
                bInheritHandle = true
            };
            securityAttributes.nLength = Marshal.SizeOf(securityAttributes);

            try
            {
                //buffer = Marshal.AllocHGlobal(securityAttributes.nLength);
                //Marshal.StructureToPtr(securityAttributes, buffer, true);

                handle = CreateFileMethod(fileName, (uint)desiredAccess, (uint)shareMode, ref securityAttributes, (uint)creationDisposition, (uint)flagsAndAttributes, templateFile);
            }
            finally
            {
                //Marshal.FreeHGlobal(buffer);
            }

            return handle;
        }
Exemplo n.º 2
0
 static internal extern IntPtr CreateFileMethod(string lpFileName, uint dwDesiredAccess, uint dwShareMode, ref SecurityAttributes lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);