Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
GetDriveType (kernel32)
.
C# Signature:
/// <summary>
/// The GetDriveType function determines whether a disk drive is a removable, fixed, CD-ROM, RAM disk, or network drive
/// </summary>
/// <param name="lpRootPathName">A pointer to a null-terminated string that specifies the root directory and returns information about the disk.A trailing backslash is required. If this parameter is NULL, the function uses the root of the current directory.</param>
[DllImport("kernel32.dll")]
public static extern DriveType GetDriveType([MarshalAs(UnmanagedType.LPStr)] string lpRootPathName);
VB Signature:
Private Declare Function GetDriveType Lib "kernel32" _
Alias "GetDriveTypeA" (ByVal lpRootPathName As String) As Integer
User-Defined Types:
C# enum:
public enum DriveType : uint
{
/// <summary>The drive type cannot be determined.</summary>
Unknown = 0, //DRIVE_UNKNOWN
/// <summary>The root path is invalid, for example, no volume is mounted at the path.</summary>
Error = 1, //DRIVE_NO_ROOT_DIR
/// <summary>The drive is a type that has removable media, for example, a floppy drive or removable hard disk.</summary>
Removable = 2, //DRIVE_REMOVABLE
/// <summary>The drive is a type that cannot be removed, for example, a fixed hard drive.</summary>
Fixed = 3, //DRIVE_FIXED
/// <summary>The drive is a remote (network) drive.</summary>
Remote = 4, //DRIVE_REMOTE
/// <summary>The drive is a CD-ROM drive.</summary>
CDROM = 5, //DRIVE_CDROM
/// <summary>The drive is a RAM disk.</summary>
RAMDisk = 6 //DRIVE_RAMDISK
}
the above prototype fails with [MarshalAs(UnmanagedType.LPStr)]. However, this works:
None.
public static extern DriveType GetDriveType([MarshalAs(UnmanagedType.LPTStr)] string lpRootPathName);
Tips & Tricks:
Please add some!
Sample Code:
Please add some!
using System.Runtime.InteropServices;
using System.IO;
namespace Volume
{
class Program
{
[DllImport("kernel32.dll")]
public static extern DriveType GetDriveType([MarshalAs(UnmanagedType.LPStr)] string lpRootPathName);
static void Main(string[] args)
{
DriveType dt = GetDriveType("D:\\");//for me this is cdrom
}
}
}
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).