Вверх ↑
Ответов: 4
Рейтинг: 0
#1: 2014-04-22 15:43:24 ЛС | профиль | цитата
Написал что то не отвечает. Может кто нибудь уже делал себе?

Вот этот код по сути выводит серийный номер. Но мне нужно чтобы он выводил серийный номер только что вставленной флешки.
unit HiAsmUnit;

interface

uses kol,Share,Debug,Windows;

type
THiAsmClass = class(TDebug)

private

public
onGetSerialNum: THI_Event;
Procedure doGetSerialNum(var _Data:TData; Index:Word);

end;

implementation
Procedure THiAsmClass.doGetSerialNum;
type
ULONG_PTR = DWORD;
//{$EXTERNALSYM ULONG_PTR}

//
// Define type for reference to device information set
//
HDEVINFO = Pointer;
//{$EXTERNALSYM HDEVINFO}

//
// Device information structure (references a device instance
// that is a member of a device information set)
//
PSPDevInfoData = ^TSPDevInfoData;
SP_DEVINFO_DATA = packed record
cbSize: DWORD;
ClassGuid: TGUID;
DevInst: DWORD; // DEVINST handle
Reserved: ULONG_PTR;
end;

//{$EXTERNALSYM SP_DEVINFO_DATA}
TSPDevInfoData = SP_DEVINFO_DATA;

TSetupDiGetDeviceRegistryPropertyA = function(DeviceInfoSet: HDEVINFO;const DeviceInfoData: TSPDevInfoData; Property_: DWORD;var PropertyRegDataType: DWORD; PropertyBuffer: PBYTE; PropertyBufferSize: DWORD;var RequiredSize: DWORD): BOOL; stdcall;
TSetupDiGetClassDevsA = function(ClassGuid: PGUID; const Enumerator: PAnsiChar;hwndParent: HWND; Flags: DWORD): HDEVINFO; stdcall;
TSetupDiEnumDeviceInfo = function(DeviceInfoSet: HDEVINFO;MemberIndex: DWORD; var DeviceInfoData: TSPDevInfoData): BOOL; stdcall;
TSetupDiGetDeviceInstanceIdA = function(DeviceInfoSet: HDEVINFO;DeviceInfoData: PSPDevInfoData; DeviceInstanceId: PAnsiChar;DeviceInstanceIdSize: DWORD; RequiredSize: PDWORD): BOOL; stdcall;
TSetupDiDestroyDeviceInfoList = function(DeviceInfoSet: HDEVINFO): BOOL; stdcall;

const
DIGCF_DEFAULT = $00000001; // only valid with DIGCF_DEVICEINTERFACE
DIGCF_PRESENT = $00000002;
DIGCF_ALLCLASSES = $00000004;
DIGCF_PROFILE = $00000008;
DIGCF_DEVICEINTERFACE = $00000010;

var
HSetupAPI, Devn:integer;
SerialNum,dtyp:DWORD;
PnPHandle: HDEVINFO;
DeviceInfo: SP_DEVINFO_DATA;
GotDev: LongBool;
PluggedIn: ulong;
DeviceInstanceId : array [0..255] of char;
RequiredSize: DWORD;
dinst, itsname, text: string;

qSetupDiGetDeviceRegistryPropertyA : TSetupDiGetDeviceRegistryPropertyA;
qSetupDiGetClassDevsA : tSetupDiGetClassDevsA;
qSetupDiEnumDeviceInfo : tSetupDiEnumDeviceInfo;
qSetupDiGetDeviceInstanceIdA : tSetupDiGetDeviceInstanceIdA;
qSetupDiDestroyDeviceInfoList : tSetupDiDestroyDeviceInfoList;
begin
HSetupAPI := LoadLibrary('SetupAPI.dll');

if HSetupAPI <> 0 then
begin
qSetupDiGetClassDevsA := GetProcAddress(HSetupAPI, 'SetupDiGetClassDevsA');
qSetupDiEnumDeviceInfo := GetProcAddress(HSetupAPI, 'SetupDiEnumDeviceInfo');
qSetupDiGetDeviceInstanceIdA := GetProcAddress(HSetupAPI, 'SetupDiGetDeviceInstanceIdA');
qSetupDiDestroyDeviceInfoList := GetProcAddress(HSetupAPI, 'SetupDiDestroyDeviceInfoList');
qSetupDiGetDeviceRegistryPropertyA := GetProcAddress(HSetupAPI,'SetupDiGetDeviceRegistryPropertyA');
end;
PnPHandle := qSetupDiGetClassDevsa(0, NIL, 0,DIGCF_ALLCLASSES or DIGCF_PRESENT);

Devn := 0;
repeat
DeviceInfo.cbSize:=sizeof(DeviceInfo);
GotDev:=qSetupDiEnumDeviceInfo(PnPHandle,Devn,DeviceInfo);
PluggedIn:=0;

if GotDev then
begin
qSetupDiGetDeviceInstanceIdA(PnPHandle,@DeviceInfo,@DeviceInstanceId,255,@RequiredSize);
_hi_OnEvent(onGetSerialNum,DeviceInstanceId);

Devn := Devn+1;
end;
until not GotDev;
FreeLibrary(HSetupAPI);
end;
end.
------------ Дoбавленo в 14.00:
Как то некоректно код добавился. Вот ссылка http://yadi.sk/d/b2vTc39xMxe5n
------------ Дoбавленo в 15.43:
хорошо я понял
карма: 1

0