Win32 API 日本語リファレンス
ホームDevices.Usb › WinUsb_ParseDescriptors

WinUsb_ParseDescriptors

関数
ディスクリプタバッファから指定種別のディスクリプタを検索する。
DLLWINUSB.dll呼出規約winapiSetLastErrorあり

シグネチャ

// WINUSB.dll
#include <windows.h>

USB_COMMON_DESCRIPTOR* WinUsb_ParseDescriptors(
    void* DescriptorBuffer,
    DWORD TotalLength,
    void* StartPosition,
    INT DescriptorType
);

パラメーター

名前方向説明
DescriptorBuffervoid*in解析対象のディスクリプタ群を含むバッファへのポインタ。
TotalLengthDWORDinDescriptorBufferの総バイト数。
StartPositionvoid*in検索を開始する位置へのポインタ。
DescriptorTypeINTin検索する対象ディスクリプタの種類(bDescriptorType値)。

戻り値の型: USB_COMMON_DESCRIPTOR*

各言語での呼び出し定義

// WINUSB.dll
#include <windows.h>

USB_COMMON_DESCRIPTOR* WinUsb_ParseDescriptors(
    void* DescriptorBuffer,
    DWORD TotalLength,
    void* StartPosition,
    INT DescriptorType
);
[DllImport("WINUSB.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr WinUsb_ParseDescriptors(
    IntPtr DescriptorBuffer,   // void*
    uint TotalLength,   // DWORD
    IntPtr StartPosition,   // void*
    int DescriptorType   // INT
);
<DllImport("WINUSB.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WinUsb_ParseDescriptors(
    DescriptorBuffer As IntPtr,   ' void*
    TotalLength As UInteger,   ' DWORD
    StartPosition As IntPtr,   ' void*
    DescriptorType As Integer   ' INT
) As IntPtr
End Function
' DescriptorBuffer : void*
' TotalLength : DWORD
' StartPosition : void*
' DescriptorType : INT
Declare PtrSafe Function WinUsb_ParseDescriptors Lib "winusb" ( _
    ByVal DescriptorBuffer As LongPtr, _
    ByVal TotalLength As Long, _
    ByVal StartPosition As LongPtr, _
    ByVal DescriptorType As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WinUsb_ParseDescriptors = ctypes.windll.winusb.WinUsb_ParseDescriptors
WinUsb_ParseDescriptors.restype = ctypes.c_void_p
WinUsb_ParseDescriptors.argtypes = [
    ctypes.POINTER(None),  # DescriptorBuffer : void*
    wintypes.DWORD,  # TotalLength : DWORD
    ctypes.POINTER(None),  # StartPosition : void*
    ctypes.c_int,  # DescriptorType : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WINUSB.dll')
WinUsb_ParseDescriptors = Fiddle::Function.new(
  lib['WinUsb_ParseDescriptors'],
  [
    Fiddle::TYPE_VOIDP,  # DescriptorBuffer : void*
    -Fiddle::TYPE_INT,  # TotalLength : DWORD
    Fiddle::TYPE_VOIDP,  # StartPosition : void*
    Fiddle::TYPE_INT,  # DescriptorType : INT
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "winusb")]
extern "system" {
    fn WinUsb_ParseDescriptors(
        DescriptorBuffer: *mut (),  // void*
        TotalLength: u32,  // DWORD
        StartPosition: *mut (),  // void*
        DescriptorType: i32  // INT
    ) -> *mut USB_COMMON_DESCRIPTOR;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WINUSB.dll", SetLastError = true)]
public static extern IntPtr WinUsb_ParseDescriptors(IntPtr DescriptorBuffer, uint TotalLength, IntPtr StartPosition, int DescriptorType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WINUSB_WinUsb_ParseDescriptors' -Namespace Win32 -PassThru
# $api::WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
#uselib "WINUSB.dll"
#func global WinUsb_ParseDescriptors "WinUsb_ParseDescriptors" sptr, sptr, sptr, sptr
; WinUsb_ParseDescriptors DescriptorBuffer, TotalLength, StartPosition, DescriptorType   ; 戻り値は stat
; DescriptorBuffer : void* -> "sptr"
; TotalLength : DWORD -> "sptr"
; StartPosition : void* -> "sptr"
; DescriptorType : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WINUSB.dll"
#cfunc global WinUsb_ParseDescriptors "WinUsb_ParseDescriptors" sptr, int, sptr, int
; res = WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
; DescriptorBuffer : void* -> "sptr"
; TotalLength : DWORD -> "int"
; StartPosition : void* -> "sptr"
; DescriptorType : INT -> "int"
; USB_COMMON_DESCRIPTOR* WinUsb_ParseDescriptors(void* DescriptorBuffer, DWORD TotalLength, void* StartPosition, INT DescriptorType)
#uselib "WINUSB.dll"
#cfunc global WinUsb_ParseDescriptors "WinUsb_ParseDescriptors" intptr, int, intptr, int
; res = WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
; DescriptorBuffer : void* -> "intptr"
; TotalLength : DWORD -> "int"
; StartPosition : void* -> "intptr"
; DescriptorType : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winusb = windows.NewLazySystemDLL("WINUSB.dll")
	procWinUsb_ParseDescriptors = winusb.NewProc("WinUsb_ParseDescriptors")
)

// DescriptorBuffer (void*), TotalLength (DWORD), StartPosition (void*), DescriptorType (INT)
r1, _, err := procWinUsb_ParseDescriptors.Call(
	uintptr(DescriptorBuffer),
	uintptr(TotalLength),
	uintptr(StartPosition),
	uintptr(DescriptorType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // USB_COMMON_DESCRIPTOR*
function WinUsb_ParseDescriptors(
  DescriptorBuffer: Pointer;   // void*
  TotalLength: DWORD;   // DWORD
  StartPosition: Pointer;   // void*
  DescriptorType: Integer   // INT
): Pointer; stdcall;
  external 'WINUSB.dll' name 'WinUsb_ParseDescriptors';
result := DllCall("WINUSB\WinUsb_ParseDescriptors"
    , "Ptr", DescriptorBuffer   ; void*
    , "UInt", TotalLength   ; DWORD
    , "Ptr", StartPosition   ; void*
    , "Int", DescriptorType   ; INT
    , "Ptr")   ; return: USB_COMMON_DESCRIPTOR*
●WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType) = DLL("WINUSB.dll", "void* WinUsb_ParseDescriptors(void*, dword, void*, int)")
# 呼び出し: WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
# DescriptorBuffer : void* -> "void*"
# TotalLength : DWORD -> "dword"
# StartPosition : void* -> "void*"
# DescriptorType : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。