Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GetFileInformationByHandle (kernel32)
 
.
Summary
Summary

C# Signature:

    [DllImport("kernel32.dll", SetLastError = true)]
    private static extern bool GetFileInformationByHandleEx(IntPtr hFile, FILE_INFO_BY_HANDLE_CLASS infoClass, out FILE_ID_BOTH_DIR_INFO dirInfo, uint dwBufferSize);

VB Signature:

Declare Function GetFileInformationByHandleEx Lib "kernel32.dll" (TODO) As TODO

User-Defined Types:

None.

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetFileInformationByHandle(
    IntPtr hFile,
    out BY_HANDLE_FILE_INFORMATION lpFileInformation
);

Alternative Managed API:

Do you know one? Please contribute it!

or, if you want to use a handle from managed code:

Notes:

http://www.pinvoke.net/default.aspx/Enums/FILE_INFO_BY_HANDLE_CLASS.html#

http://www.pinvoke.net/default.aspx/Structures/FILE_ID_BOTH_DIR_INFO.html

http://www.pinvoke.net/default.aspx/Structures.LargeInteger

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool GetFileInformationByHandle(
    Microsoft.Win32.SafeHandles.SafeFileHandle hFile,
    out BY_HANDLE_FILE_INFORMATION lpFileInformation
);

Tips & Tricks:

Please add some!

VB.NET Signature:

Declare Auto Function GetFileInformationByHandle Lib "kernel32.dll" (ByVal hFile As IntPtr, ByRef lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Boolean

Sample Code:

    internal static Int64 GetDirectoryId(string dir)
    {
        var handle = CreateFile(dir, FileAccess.Read, FileShare.Read, IntPtr.Zero, FileMode.Open, 0x02000000 | 0x00000080, IntPtr.Zero);
        var fileStruct = new FILE_ID_BOTH_DIR_INFO();
        GetFileInformationByHandleEx(handle, FILE_INFO_BY_HANDLE_CLASS.FileIdBothDirectoryInfo, out fileStruct, (uint)Marshal.SizeOf(fileStruct));
        CloseHandle(handle);
        var win32Error = Marshal.GetLastWin32Error();
        if (win32Error != 0)
        throw new Win32Exception();

User-Defined Types:

http://pinvoke.net/default.aspx/Structures/BY_HANDLE_FILE_INFORMATION.html

        return fileStruct.FileId.QuadPart;
    }

Notes:

None.

Documentation

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions