up 有分, 不够再加。

解决方案 »

  1.   

    char Buf[128];
    char *p;
    UINT Type;
    GetLogicalDriveStrings(128,Buf);
    for(p=Buf;*p;p+=lstrlen(p)+1)
    {
          Type=GetDriveType(p);
          switch(Type)
          {
           case DRIVE_UNKNOWN: //The drive type cannot be determined. 
           case DRIVE_NO_ROOT_DIR: //The root directory does not exist. 
           case DRIVE_REMOVABLE: //The disk can be removed from the drive. 
           case DRIVE_FIXED: //The disk cannot be removed from the drive. 
           case DRIVE_REMOTE: //The drive is a remote (network) drive. 
           case DRIVE_CDROM: //The drive is a CD-ROM drive. 
           case DRIVE_RAMDISK: //The drive is a RAM disk. 
           Default:
           }
      

  2.   

    void CDrvSrlNmbrDlg::FindAllDrivers()
    {
    CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
    DWORD dwNumBytesForDriveStrings;//实际存储驱动器号的字符串长度
    HANDLE hHeap;
    LPSTR lp;
    CString strLogdrive; //获得实际存储驱动器号的字符串长度
    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); //将驱动器一个个放到下拉框中
    while (*lp!=0) {
    Driver->AddString(lp);
    lp=_tcschr(lp,0)+1;
    }
    }
    else 
    AfxMessageBox("Can't Use The Function GetLogicalDriveStrings!");
    }
      

  3.   

    GetLogicalDriveStrings(128,Buf);???两位老大,  我的一个磁盘还没有分区呢, 所以根本没有盘符, 用GetLogicalDriveStrings(128,Buf), 根本获得不了,  再帮我想想办法吧, 谢谢了.
      

  4.   

    void CDrvSpaceDlg::FindAllDrivers()
    {
    CComboBox* Driver=(CComboBox*)GetDlgItem(IDC_DRIVER);
    DWORD dwNumBytesForDriveStrings;//实际存储驱动器号的字符串长度
    HANDLE hHeap;
    LPSTR lp;
    CString strLogdrive; //获得实际存储驱动器号的字符串长度
    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); //将驱动器一个个放到下拉框中
    while (*lp!=0) {
    Driver->AddString(lp);
    lp=_tcschr(lp,0)+1;
    }
    }
    else 
    AfxMessageBox("Can't Use The Function GetLogicalDriveStrings!");
    }
      

  5.   


    #include <stdio.h>
    #include <windows.h>
    #include <setupapi.h>
    #include <devguid.h>
    #include <regstr.h>#pragma comment(lib,"Setupapi.lib")
    int main( )
    {
        HDEVINFO hDevInfo;
        SP_DEVINFO_DATA DeviceInfoData;
        DWORD i;
        GUID aa;
    GUID *ab;
    ab=&aa;
    i=sizeof(GUID);
            DWORD DataT;
    char buf[255];
    memset(buf,0,256);
            LPTSTR buffer = buf;
            DWORD buffersize = 0;
      if(!SetupDiClassGuidsFromName("CDROM",ab,i,&i))//通过设备类名得到设备类型的GUID
      {
      printf("false");
      return 1;
      }
       printf("设备GUID=%d-%d-%d-%d\n",ab->Data1,ab->Data2,ab->Data3,ab->Data4);
      
        hDevInfo = SetupDiGetClassDevs(ab, 0, 0, 0);//通过设备类型GUID得到这类设备信息的句柄
        if (hDevInfo == INVALID_HANDLE_VALUE)
        {
            // Insert error handling here.
            return 1;
        }
           
        // Enumerate through all devices in Set.
         
        DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
        for (i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, &DeviceInfoData); i++)//枚举这类设备中所有的设备
        {         for(int s=0;s<2;s++)//因为有些时候第一次调用SetupDiGetDeviceRegistryProperty可能会失败,所以调用两次,
    {
    SetupDiGetDeviceRegistryProperty(hDevInfo, &DeviceInfoData, SPDRP_DEVICEDESC,
    &DataT, (PBYTE)buffer, buffersize, &buffersize);//得到设备属性
    }

     printf("设备: [ %s size=%d ]\n",buffer,buffersize);
     memset(buf,0,256);
                 } 
        if ( GetLastError()!=NO_ERROR && GetLastError()!=ERROR_NO_MORE_ITEMS )
        {
            // Insert error handling here.
            return 1;
        }
           
        //  Cleanup
        SetupDiDestroyDeviceInfoList(hDevInfo);
           
        return 0;
    }
    上面代码是通过设备类型名来获得本机安装到的设备,测试结果
    设备GUID=1295444325-58149-4558-1245012
    设备: [ CD-ROM Drive size=13 ]
    设备: [ CD-ROM Drive size=13 ]
    设备: [ CD-ROM Drive size=13 ]
    设备: [ CD-ROM Drive size=13 ]
    Press any key to continue
    可以通过SetupDiGetDeviceRegistryProperty的参数来得到指定设备的各项可能信息下面是一些设备的类型名
    USB
    Prots  并口串口
    CDROM
    MEDIA  媒体设备
    hdc  IDE
    DiskDrive 硬盘设备
    Display 显示器
    HIDClass 输入设备
    Image  可能是移动存储设备
    SCSIAdapter SCSI适配器设备例如你可以选择MEDIA 下面是MEDIA的测试结果
    设备GUID=1295444332-58149-4558-1245012
    设备: [ Game Port for Creative  size=24 ]
    设备: [ Unimodem Half-Duplex Audio Device size=34 ]
    设备: [ SB PCI(WDM) size=12 ]
    设备: [ YAMAHA XG SoftSynthesizer size=26 ]
    设备: [ Virtual Sound Canvas 3.2 size=25 ]
    设备: [ 音频编码解码器 size=8 ]
    设备: [ 传统音频 size=9 ]
    设备: [ 媒体控制 size=7 ]
    设备: [ 传统视频 size=9 ]
    设备: [ 视频编码 size=8 ]
    设备: [ BDA Slip De-Framer size=19 ]
    设备: [ NABTS/FEC VBI Codec size=20 ]
    设备: [ Closed Caption Decoder size=23 ]
    设备: [ Microsoft Kernel GS Wavetable Synthesizer size=42 ]
    设备: [ World Standard Teletext Codec size=30 ]
    设备: [ Microsoft DirectMusic SW Synth (WDM) size=37 ]
    设备: [ BDA MPE Filter size=15 ]
    设备: [ Microsoft Streaming Service Proxy size=34 ]
    设备: [ Microsoft Streaming Clock Proxy size=32 ]
    设备: [ Microsoft Kernel System Renderer size=33 ]
    设备: [ Microsoft Kernel Audio Mixer size=29 ]
    设备: [ Microsoft Streaming Network Raw Channel Access size=47 ]
    设备: [ Microsoft Streaming Network Raw Channel Access size=47 ]
    设备: [ Microsoft Streaming Network Raw Channel Access size=47 ]
    设备: [ Microsoft WINMM WDM Audio Compatibility Driver size=47 ]
    设备: [ Microsoft Streaming Tee/Sink-to-Sink Converter size=47 ]
    设备: [ Microsoft Streaming Tee/Sink-to-Sink Converter size=47 ]
    设备: [ BDA IPSink size=11 ]
    设备: [ Microsoft Streaming Quality Manager Proxy size=42 ]
    设备: [ YAMAHA XG SoftSynthesizer size=26 ]
    Press any key to continue
    如果还想找到一些别的想要知道的设备,可以在设备管理器中察看驱动,找到他的.INF,察看设备类型就行了