Вверх ↑
Ответов: 758
Рейтинг: 112
#1: 2014-04-20 19:58:09 ЛС | профиль | цитата
nesco писал(а):
А вот сейчас последует следующий вопрос -- как это все реализовать на HiAsm-e

Вот пример подключения стандартной библиотеки SetupAPI.dll
code_33449.txt

Описания функций можно посмотреть внутри - setupapi.pas
------------ Дoбавленo в 19.58:
miver писал(а):
Че-то не вставляется нормально схема у меня. В IC неполный код получается
Почему-то форум обрезает
Вот текст IC

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.
карма: 1

0
файлы: 1code_33449.txt [4.6KB] [364]