阅读:1052回复:1
想要找到系统中安装的某一型号的光驱
应该怎么做?应用程序和光驱的交互过程是怎样的?谢谢!
|
|
沙发#
发布于:2004-08-13 07:53
根据光驱的GUID用以下Setup API找到光驱设备对象的symbollink name然后用CreateFile,ReadFile, WriteFile,DeviceIoControl来操作光驱,
HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if(info==INVALID_HANDLE_VALUE) { printf(cError, "No HDEVINFO available for this GUID , error code %u", GetLastError()); OutputDebugString(cError); return NULL; } // Get interface data for the requested instance SP_INTERFACE_DEVICE_DATA ifdata; ifdata.cbSize = sizeof(ifdata); if(!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, instance, &ifdata)) { printf(cError, "No SP_INTERFACE_DEVICE_DATA available for this GUID instance , error code %u", GetLastError()); OutputDebugString(cError); SetupDiDestroyDeviceInfoList(info); return NULL; } // Get size of symbolic link name DWORD ReqLen; SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL); PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]); if( ifDetail==NULL) { SetupDiDestroyDeviceInfoList(info); return NULL; } // Get symbolic link name ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL)) { SetupDiDestroyDeviceInfoList(info); delete ifDetail; return NULL; } // Open file HANDLE rv = CreateFile( ifDetail->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( rv==INVALID_HANDLE_VALUE) rv = NULL; delete ifDetail; SetupDiDestroyDeviceInfoList(info); 不明白找我:MSN:xingxueping@hotmail.com |
|