Skip to content

It would be nice is SafeHFILE and SafeHCFFILE were more compatible #576

@catmanjan

Description

@catmanjan

I'm trying to build an abstraction where a function can return a handle from either createfile or cfopenfilewithoplock, e.g.

        public static HFILE GetHandle(string filePath)
        {
            if (File.Exists(filePath))
            {
                return Kernel32.CreateFile(filePath, 0, 0, dwCreationDisposition: FileMode.Open, dwFlagsAndAttributes: FileFlagsAndAttributes.FILE_ATTRIBUTE_NORMAL);
            }
            else if (Directory.Exists(filePath))
            {
                CfOpenFileWithOplock(filePath, CF_OPEN_FILE_FLAGS.CF_OPEN_FILE_FLAG_NONE, out var protectedHandle);

                return protectedHandle;
            }

            return HFILE.INVALID_HANDLE_VALUE;
        }

Both of these functions return safe___ file objects, so if it were possible to change the return type of the function to be a common type I could then dispose of it more neatly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions