您的位置:首页 > 其它

GetLogicalDriveStrings()和GetDirveType()

2008-06-28 17:21 453 查看
GetLogicalDriveStrings()

win32 API中获取系统分区信息的函数。。

DWORD GetLogicalDriveStrings(
DWORD nBufferLength,  // size of buffer
  LPTSTR lpBuffer       // drive strings buffer
);

nBufferLength [in] Specifies the maximum size, in characters, of the buffer pointed to by lpBuffer. This size does not include the terminating null character. lpBuffer [out] Pointer to a buffer that receives a series of null-terminated strings, one for each valid drive in the system, that end with a second null character. The following example shows the buffer contents with <null> representing the terminating null character. 

函数将所有盘符信息以lpBuffer返回,以譬如 "A:\<null>C:\<null>F:\<null><null>"这样的格式。。

当然。我们可以将其分离出来。。大致代码如下:

DWORD len;

char *pBuffer=new char[30];

devl=GetLogicalDriveStrings(100,dev);

string DvName[20];

int n=0;

while(*pBuffer)

{

DvName[n++]=pBuffer;

while(*dev!='\0')dev++;

dev++;

}

GetDirveType()

win32 API中获取分区类型的函数。。

UINT GetDriveType(
LPCTSTR lpRootPathName   // root directory
);

lpRootPathName 包含了根目录路径的字符串指针

返回值

DRIVE_UNKNOWN 未知的磁盘类型

DRIVE_NO_ROOT_DIR 说明lpRootPathName是无效的

DRIVE_REMOVABLE 可移动磁盘

DRIVE_FIXED 固定磁盘

DRIVE_REMOTE 网络磁盘

DRIVE_CDROM 光驱

DRIVE_RAMDISK 为RAM

借助这两个函数。我们便可在程序中。获取系统的分区信息和各分区的类型。。结合一下。也可以用来确定我们要找的分区
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: