up 有分, 不够再加。
解决方案 »
- RichEdit问题
- 如何对页面中的框架指定加载
- 在DllMain中调用CreateThread为什么不能成功?
- 使用ScrollView,拖动滚动条,图形重叠的问题?
- 如何在通过dll打开一个对话框 a ,a又打开另一对话框 b,b又打开一个c对话框,如何定义使得 c中可以用a 中定义的变量。
- *** <绝对难题> A交换机 的一个网络模块口, 再挂台 B交换机 上去, B交换机 的电脑能上网吗? ***
- 急!,启动线程,传递一个带CStringArray的类,总是运行提示错误,代码简要如下
- 数据压缩!
- 关于Paint的两个小问题,望指教!!!
- 如果ShellExecute()不可以,还有什么办法么?请举例。
- 有关于 DSN 问题,急呀,帮帮忙~~~
- 怎么用vc绘制数学函数的图象
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:
}
{
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!");
}
{
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!");
}
#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,察看设备类型就行了