Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.118.227.69] |
|
Сообщ.
#1
,
|
|
|
Всем доброго времени суток.
Есть такая функция с описанием \brief Creates USB interface enumerator This routine enumerates all USB interfaces that match provided class ID. This routine uses SetupDiGetClassDevs SDK routine to enumerate devices that match class ID and then SetupDiEnumDeviceInterfaces SDK routine is called to enumerate interfaces on the devices. @param[in] class_id Device class ID, assigned by the driver. @param[in] exclude_not_present If true enumation will include only those devices that are currently present. @param[in] exclude_removed If true interfaces with SPINT_REMOVED flag set will be not included in the enumeration. @param[in] active_only If true only active interfaces (with flag SPINT_ACTIVE set) will be included in the enumeration. @return Handle to the enumerator object or NULL on failure. If NULL is returned GetLastError() provides extended error information. */ typedef void* ADBAPIHANDLE; ADBWIN_API ADBAPIHANDLE __cdecl AdbEnumInterfaces(GUID class_id, bool exclude_not_present, bool exclude_removed, bool active_only); В Delphi вызываю так type ADBAPIHANDLE = Pointer; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; AdbLoad: THandle; enum_handle: ADBAPIHANDLE; AdbEnumInterfaces: function(class_id: TGUID; exclude_not_present: Boolean; exclude_removed: Boolean; active_only: Boolean): ADBAPIHANDLE; cdecl; implementation {$R *.dfm} Procedure LoadMyLibrary(FileName: String); begin AdbLoad := LoadLibrary(PWideChar(FileName)); if AdbLoad = 0 then begin MessageBox(0,'Невозможно загрузить библиотеку',0,0); exit; end; AdbEnumInterfaces := GetProcAddress(Adbload, 'AdbEnumInterfaces'); AdbNextInterface := GetProcAddress(AdbLoad, 'AdbNextInterface'); //AdbCloseHandle := GetProcAddress(AdbLoad, 'AdbCloseHandle'); if @AdbEnumInterfaces = nil then begin MessageBox(0,'Невозможно загрузить библиотеку',0,0); exit; end; if @AdbNextInterface = nil then begin MessageBox(0,'Невозможно загрузить библиотеку',0,0); exit; end; end; procedure TForm1.Button1Click(Sender: TObject); const ANDROID_USB_CLASS_ID: TGUID = '{F72FE0D4-CBCB-407d-8814-9ED673D0DD6B}'; begin enum_handle := AdbEnumInterfaces(ANDROID_USB_CLASS_ID, True, True, True); end; procedure TForm1.FormCreate(Sender: TObject); begin LoadMyLibrary('AdbWinApi.dll'); end; procedure TForm1.FormDestroy(Sender: TObject); begin FreeLibrary(Adbload); end; end. Функция возвращает всегда 1 , а не Handle Где я не правильно делаю? А вот пример использования на С const GUID kAdbInterfaceId = ANDROID_USB_CLASS_ID; bool TestEnumInterfaces() { // Enumerate interfaces ADBAPIHANDLE enum_handle = AdbEnumInterfaces(kAdbInterfaceId, true, true, true); if (NULL == enum_handle) { printf("\nEnum interfaces failure:"); printf("\nUnable to enumerate ADB interfaces: %u", GetLastError()); return false; } |
Сообщ.
#2
,
|
|
|
Цитата Сержик @ Функция возвращает всегда 1 , а не Handle А ты считаешь, что Handle не может иметь значение = 1? |
Сообщ.
#3
,
|
|
|
Не знаю
Я еще новичек Добавлено А здесь тогда как? typedef struct _AdbInterfaceInfo { /// Inteface's class id (see SP_DEVICE_INTERFACE_DATA for details) GUID class_id; /// Interface flags (see SP_DEVICE_INTERFACE_DATA for details) unsigned long flags; /// Device name for the interface (see SP_DEVICE_INTERFACE_DETAIL_DATA /// for details) wchar_t device_name[1]; } AdbInterfaceInfo; @param[in] adb_handle Handle to interface enumerator object obtained via AdbEnumInterfaces call. @param[out] info Upon successful completion will receive interface information. Can be NULL. If it is NULL, upon return from this routine size parameter will contain memory size required for the next entry. @param[in,out] size On the way in provides size of the memory buffer addressed by info parameter. On the way out (only if buffer was not big enough) will provide memory size required for the next entry. @return true on success, false on error. If false is returned GetLastError() provides extended error information. ERROR_INSUFFICIENT_BUFFER indicates that buffer provided in info parameter was not big enough and size parameter contains memory size required for the next entry. ERROR_NO_MORE_ITEMS indicates that enumeration is over and there are no more entries to return. */ ADBWIN_API bool __cdecl AdbNextInterface(ADBAPIHANDLE adb_handle, AdbInterfaceInfo* info, unsigned long* size); |
Сообщ.
#4
,
|
|
|
Цитата Сержик @ А здесь тогда как? Чего как? Первым параметром - полученный хэндл, вторым - указатель на структуру AdbInterfaceInfo, третим - размер этой структуры. PS: Поскольку в структуре AdbInterfaceInfo под device_name отведен всего один символ, то подразумевается динамическое выделение памяти - сначала вызываешь функцию с info = nil и получаешь size = требуемому размеру, затем выделяешь память по GetMem и передаешь указатель в функцию вместо info |
Сообщ.
#5
,
|
|
|
Пробывал, возвращает всегда False
Еще заметил если несколько раз вызвать первую функцию , то Handle увеличивается по порядку 1 потом 2 и т.д |
Сообщ.
#6
,
|
|
|
Цитата Сержик @ Пробывал, возвращает всегда False 1) Вызови GetLastError и посмотри в своем sdk, что означает код ошибки 2) Покажи как пробовал, может что-то не так... Цитата Сержик @ Еще заметил если несколько раз вызвать первую функцию , то Handle увеличивается по порядку 1 потом 2 и т.д Ну и что? Значит это просто порядковый индекс чего-то |
Сообщ.
#7
,
|
|
|
GetLastError ,ошибку не показал
|
Сообщ.
#8
,
|
|
|
ADBWIN_API ADBAPIHANDLE __cdecl AdbEnumInterfaces(GUID class_id, bool exclude_not_present, bool exclude_removed, bool active_only); AdbEnumInterfaces: function(class_id: TGUID; exclude_not_present: Boolean; exclude_removed: Boolean; active_only: Boolean): ADBAPIHANDLE; cdecl; bool (4 байта) <> Boolean (1 байт) |
Сообщ.
#9
,
|
|
|
На дельфи эта структура
typedef struct _AdbInterfaceInfo { GUID class_id; unsigned long flags; wchar_t device_name[1]; } AdbInterfaceInfo; так будет ? AdbInterfaceInfo = packed record class_id: TGUID; flags : DWORD; device_name: PWideChar; end; |
Сообщ.
#10
,
|
|
|
Цитата Сержик @ так будет ? Нет, конечно. device_name - не указатель на массив, а сам массив из одного элемента array[0..0] of WideChar. Хотя можно и сразу задать массив "достаточной длины", например [0..255] PS: А говоришь "Пробовал"... |
Сообщ.
#11
,
|
|
|
переделал
AdbInterfaceInfo = packed record class_id: TGUID; flags : DWORD; device_name: array [0..255] of WideChar; end; |
Сообщ.
#12
,
|
|
|
Цитата Filka @ bool (4 байта) <> Boolean (1 байт) А с чего ты взял, что bool - 4 байта? Это же не виндовый BOOL, а стандартный сишный bool, размер которого не регламентирован. Но из соображений совместимости в большинстве компиляторов используется минимальный размер bool в 1 байт со значениями false\true = 0\1. |
Сообщ.
#13
,
|
|
|
Сержик AdbNextInterface source help me ? not found unit...
|