网上找到一个VFP的,但没用
Clear
Local ans, DeviceNumber, DiskGUID, hSetup, Success, i, dia, da, didd
#Define GUID_DEVINTERFACE_USB_DEVICE "A5DCBF10-6530-11D2-901F-00C04FB951ED"
#Define INVALID_HANDLE_VALUE -1
#Define BUFFER_SIZE 2048
#Define REG_SZ 1
#Define GENERIC_WRITE 0x40000000
#Define FILE_SHARE_WRITE 0x2
#Define OPEN_EXISTING 0x3
#Define FILE_ATTRIBUTE_NORMAL 128
#Define DIGCF_PRESENT 0x2
#Define DIGCF_DEVICEINTERFACE 0x10
Declare Integer SetupDiGetClassDevs In "setupapi.dll" ;
String @ClassGuid, ;
Integer Enumerator, ;
Integer hwndParent, ;
Integer Flags
Declare Integer SetupDiEnumDeviceInterfaces In "setupapi.dll" ;
Integer DeviceInfoSet, ;
Integer DeviceInfoData, ;
String InterfaceClassGuid, ;
Integer MemberIndex, ;
String @DeviceInterfaceData
Declare Integer SetupDiDestroyDeviceInfoList In "setupapi.dll" ;
Integer DeviceInfoSet
Declare Integer SetupDiGetDeviceInterfaceDetail In "setupapi.dll" ;
Integer DeviceInfoSet, ;
String DeviceInterfaceData, ;
String @DeviceInterfaceDetailData, ;
Integer DeviceInterfaceDetailDataSize, ;
Integer @RequiredSize, ;
String @DeviceInfoData
Declare INTEGER CreateFile IN kernel32;
STRING lpFileName,INTEGER dwDesiredAccess,INTEGER dwShareMode,;
INTEGER lpSecurityAttr,INTEGER dwCreationDisp,INTEGER dwFlagsAndAttrs,;
INTEGER hTemplateFile
DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject
DECLARE INTEGER DeviceIoControl IN kernel32;
INTEGER hDevice,;
INTEGER dwIoControlCode,;
STRING @ lpInBuffer,;
INTEGER nInBufferSize,;
STRING @ lpOutBuffer,;
INTEGER nOutBufferSize,;
INTEGER @ lpBytesReturned,;
INTEGER lpOverlapped
DECLARE Long GetLastError IN WIN32API
**ÕaÖÖ»ñè¡μÄGUID2»DD
DiskGUID = guid(GUID_DEVINTERFACE_USB_DEVICE)
**ÕaÖÖ»ñè¡μÄGUID¿éòÔ£¬μ«Ö»Äüè¡μ½¼üÅìμÄDÅÏ¢£¬¿éêÇÔõÃ′»ñμÃÆäËûUSBé豸μÄDÅÏ¢ÄØ£¿
**oíòÔÇ°·¢μÄ′úÂëÖ»óDÕaàï2»í¬
DECLARE HidD_GetHidGuid IN HID STRING @ HidGuid
DiskGUID=REPLICATE(CHR(0),16)
HidD_GetHidGuid(@DiskGUID)
hSetup = SetupDiGetClassDevs(DiskGUID, 0, 0, Bitor(DIGCF_PRESENT, DIGCF_DEVICEINTERFACE))
*!*
WINSETUPAPI HDEVINFO SetupDiGetClassDevsW(
*!*
[in, optional] const GUID *ClassGuid,
*!*
[in, optional] PCWSTR
Enumerator,
*!*
[in, optional] HWND
hwndParent,
*!*
[in]
DWORD
Flags
*!*
)
If hSetup <> INVALID_HANDLE_VALUE
i = 0
Success=1
Do While Success<>0
dia = dword2str(28)+Replicate(Chr(0),16)+Replicate(Chr(0),4)+Replicate(Chr(0),4)
Success = SetupDiEnumDeviceInterfaces(hSetup, 0, DiskGUID, i, @dia)
If Success <> 0
da = dword2str(28)+Replicate(Chr(0),16)+Replicate(Chr(0),4)+Replicate(Chr(0),4)
didd = dword2str(5)+Replicate(Chr(0),BUFFER_SIZE)
nBytes = BUFFER_SIZE
nRequiredSize = 0
m.err1 = SetupDiGetDeviceInterfaceDetail(hSetup, dia, @didd, nBytes, @nRequiredSize, @da)
didd=SUBSTR(didd,5)
didd=LEFT(didd,AT(CHR(0),didd)-1)
hhcd=CreateFile(didd, GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0)
Declare LONG HidD_GetProductString IN "HID.dll" LONG Handle,STRING @BufferPtr, LONG Length
Declare LONG HidD_GetSerialNumberString IN "HID.dll" LONG Handle , STRING @BufferPtr, LONG Length
Declare LONG HidD_GetManufacturerString IN "HID.dll" LONG Handle , STRING @BufferPtr, LONG Length
Declare LONG HidD_GetPhysicalDescriptor IN "HID.dll" LONG Handle , STRING @BufferPtr, LONG Length
STU=REPLICATE(CHR(0),256)
HidD_GetManufacturerString( hHcd,@STU,256)
STU=STRCONV(STU,6)
?LEFT(STU,AT(CHR(0),STU)-1),"1"
STU=REPLICATE(CHR(0),256)
HidD_GetProductString( hHcd,@STU,256)
STU=STRCONV(STU,6)
?LEFT(STU,AT(CHR(0),STU)-1),"2"
STU=REPLICATE(CHR(0),256)
HidD_GetSerialNumberString( hHcd,@STU,256)
?LEFT(STU,AT(CHR(0),STU)-1),"3"
IF hhcd <>INVALID_HANDLE_VALUE
CloseHandle(hHcd)
endif
Endif
i = i+1
Enddo
Endif
SetupDiDestroyDeviceInfoList(hSetup)
Return
Function Guid
Lparameter m.guid
m.guid=Chrtran(m.guid,"{}-","")
Return ;
word2str(Eval("0x"+Substr(m.guid,5,4)))+ ;
word2str(Eval("0x"+Substr(m.guid,1,4)))+ ;
word2str(Eval("0x"+Substr(m.guid,9,4)))+ ;
word2str(Eval("0x"+Substr(m.guid,13,4)))+ ;
chr(Eval("0x"+Substr(m.guid,17,2)))+ ;
chr(Eval("0x"+Substr(m.guid,19,2)))+ ;
chr(Eval("0x"+Substr(m.guid,21,2)))+ ;
chr(Eval("0x"+Substr(m.guid,23,2)))+ ;
chr(Eval("0x"+Substr(m.guid,25,2)))+ ;
chr(Eval("0x"+Substr(m.guid,27,2)))+ ;
chr(Eval("0x"+Substr(m.guid,29,2)))+ ;
chr(Eval("0x"+Substr(m.guid,31,2)))
ENDFUNC
Function dword2str
Lparameter m.wrd
Local m.wrd1, m.st1
m.wrd1=m.wrd%4294967296
Declare RtlMoveMemory In Win32API String @st1, Integer @wrd, Integer Cnt
m.st1=Chr(0)+Chr(0)+Chr(0)+Chr(0)
RtlMoveMemory(@m.st1, @m.wrd, 4)
Return m.st1
ENDFUNC
Function word2str
Lparameter m.wrd
Local m.wrd1, m.st1
m.wrd1=m.wrd%65536
Declare RtlMoveMemory In Win32API String @st1, Integer @wrd, Integer Cnt
m.st1=Chr(0)+Chr(0)
RtlMoveMemory(@m.st1, @m.wrd, 2)
Return m.st1
ENDFUNC
以下是C如何列出设备
DeviceInfoSet = SetupDiGetClassDevs(
NULL,
NULL,
NULL,
DIGCF_ALLCLASSES | DIGCF_PRESENT);
ZeroMemory(&DeviceInfoData, sizeof(SP_DEVINFO_DATA));
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
DeviceIndex = 0;
while (SetupDiEnumDeviceInfo(
DeviceInfoSet,
DeviceIndex,
&DeviceInfoData)) {
DeviceIndex++;
if (!SetupDiGetDeviceProperty(
DeviceInfoSet,
&DeviceInfoData,
&DEVPKEY_Device_Class,
&PropType,
(PBYTE)&DevGuid,
sizeof(GUID),
&Size,
0) || PropType != DEVPROP_TYPE_GUID) {
Error = GetLastError();
if (Error == ERROR_NOT_FOUND) {
\\
\\ This device has an unknown device setup class.
\\
}
}
}
if (DeviceInfoSet) {
SetupDiDestroyDeviceInfoList(DeviceInfoSet);
}