void FindDriverInfo()
{
CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
DWORD dwNumBytesForDriveStrings;
HANDLE hHeap;
LPSTR lp;
CString strLogdrive;
int nNumDrives=0, nDriveNum;
dwNumBytesForDriveStrings=GetLogicalDriveStrings(0,NULL)
*sizeof(TCHAR);//实际存储驱动器号的字符串长度
if (dwNumBytesForDriveStrings!=0) {
hHeap=GetProcessHeap();
lp=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,
dwNumBytesForDriveStrings);//
GetLogicalDriveStrings(HeapSize(hHeap,0,lp),lp);
StringBox.SetSize(dwNumBytesForDriveStrings/sizeof(TCHAR)+1);
while (*lp!=0) {
if (GetDriveType(lp)==DRIVE_REMOVABLE){
Driver->AddString(lp);
StringBox[nNumDrives]=lp;
nNumDrives++;
}
lp=_tcschr(lp,0)+1;
}
}
else AfxMessageBox("Can't Use The Function GetLogicalDriveStrings!");
}
{
CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
DWORD dwNumBytesForDriveStrings;
HANDLE hHeap;
LPSTR lp;
CString strLogdrive;
int nNumDrives=0, nDriveNum;
dwNumBytesForDriveStrings=GetLogicalDriveStrings(0,NULL)
*sizeof(TCHAR);//实际存储驱动器号的字符串长度
if (dwNumBytesForDriveStrings!=0) {
hHeap=GetProcessHeap();
lp=(LPSTR)HeapAlloc(hHeap,HEAP_ZERO_MEMORY,
dwNumBytesForDriveStrings);//
GetLogicalDriveStrings(HeapSize(hHeap,0,lp),lp);
StringBox.SetSize(dwNumBytesForDriveStrings/sizeof(TCHAR)+1);
while (*lp!=0) {
if (GetDriveType(lp)==DRIVE_REMOVABLE){
Driver->AddString(lp);
StringBox[nNumDrives]=lp;
nNumDrives++;
}
lp=_tcschr(lp,0)+1;
}
}
else AfxMessageBox("Can't Use The Function GetLogicalDriveStrings!");
}
博客展示了一个名为 FindDriverInfo 的函数代码,该函数用于查找可移动驱动器信息。通过 GetLogicalDriveStrings 函数获取驱动器号字符串长度,分配内存存储信息,遍历字符串,若为可移动驱动器则添加到组合框中,若函数无法使用则给出提示。
1140

被折叠的 条评论
为什么被折叠?



