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)。
const std = @import("std");

extern "winusb" fn WinUsb_ParseDescriptors(
    DescriptorBuffer: ?*anyopaque, // void*
    TotalLength: u32, // DWORD
    StartPosition: ?*anyopaque, // void*
    DescriptorType: i32 // INT
) callconv(std.os.windows.WINAPI) [*c]USB_COMMON_DESCRIPTOR;
proc WinUsb_ParseDescriptors(
    DescriptorBuffer: pointer,  # void*
    TotalLength: uint32,  # DWORD
    StartPosition: pointer,  # void*
    DescriptorType: int32  # INT
): ptr USB_COMMON_DESCRIPTOR {.importc: "WinUsb_ParseDescriptors", stdcall, dynlib: "WINUSB.dll".}
pragma(lib, "winusb");
extern(Windows)
USB_COMMON_DESCRIPTOR* WinUsb_ParseDescriptors(
    void* DescriptorBuffer,   // void*
    uint TotalLength,   // DWORD
    void* StartPosition,   // void*
    int DescriptorType   // INT
);
ccall((:WinUsb_ParseDescriptors, "WINUSB.dll"), stdcall, Ptr{USB_COMMON_DESCRIPTOR},
      (Ptr{Cvoid}, UInt32, Ptr{Cvoid}, Int32),
      DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
# DescriptorBuffer : void* -> Ptr{Cvoid}
# TotalLength : DWORD -> UInt32
# StartPosition : void* -> Ptr{Cvoid}
# DescriptorType : INT -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void* WinUsb_ParseDescriptors(
    void* DescriptorBuffer,
    uint32_t TotalLength,
    void* StartPosition,
    int32_t DescriptorType);
]]
local winusb = ffi.load("winusb")
-- winusb.WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
-- DescriptorBuffer : void*
-- TotalLength : DWORD
-- StartPosition : void*
-- DescriptorType : INT
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WINUSB.dll');
const WinUsb_ParseDescriptors = lib.func('__stdcall', 'WinUsb_ParseDescriptors', 'void *', ['void *', 'uint32_t', 'void *', 'int32_t']);
// WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
// DescriptorBuffer : void* -> 'void *'
// TotalLength : DWORD -> 'uint32_t'
// StartPosition : void* -> 'void *'
// DescriptorType : INT -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WINUSB.dll", {
  WinUsb_ParseDescriptors: { parameters: ["pointer", "u32", "pointer", "i32"], result: "pointer" },
});
// lib.symbols.WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType)
// DescriptorBuffer : void* -> "pointer"
// TotalLength : DWORD -> "u32"
// StartPosition : void* -> "pointer"
// DescriptorType : INT -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void* WinUsb_ParseDescriptors(
    void* DescriptorBuffer,
    uint32_t TotalLength,
    void* StartPosition,
    int32_t DescriptorType);
C, "WINUSB.dll");
// $ffi->WinUsb_ParseDescriptors(DescriptorBuffer, TotalLength, StartPosition, DescriptorType);
// DescriptorBuffer : void*
// TotalLength : DWORD
// StartPosition : void*
// DescriptorType : INT
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Winusb extends StdCallLibrary {
    Winusb INSTANCE = Native.load("winusb", Winusb.class);
    Pointer WinUsb_ParseDescriptors(
        Pointer DescriptorBuffer,   // void*
        int TotalLength,   // DWORD
        Pointer StartPosition,   // void*
        int DescriptorType   // INT
    );
}
@[Link("winusb")]
lib LibWINUSB
  fun WinUsb_ParseDescriptors = WinUsb_ParseDescriptors(
    DescriptorBuffer : Void*,   # void*
    TotalLength : UInt32,   # DWORD
    StartPosition : Void*,   # void*
    DescriptorType : Int32   # INT
  ) : USB_COMMON_DESCRIPTOR*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WinUsb_ParseDescriptorsNative = Pointer<Void> Function(Pointer<Void>, Uint32, Pointer<Void>, Int32);
typedef WinUsb_ParseDescriptorsDart = Pointer<Void> Function(Pointer<Void>, int, Pointer<Void>, int);
final WinUsb_ParseDescriptors = DynamicLibrary.open('WINUSB.dll')
    .lookupFunction<WinUsb_ParseDescriptorsNative, WinUsb_ParseDescriptorsDart>('WinUsb_ParseDescriptors');
// DescriptorBuffer : void* -> Pointer<Void>
// TotalLength : DWORD -> Uint32
// StartPosition : void* -> Pointer<Void>
// DescriptorType : INT -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WinUsb_ParseDescriptors(
  DescriptorBuffer: Pointer;   // void*
  TotalLength: DWORD;   // DWORD
  StartPosition: Pointer;   // void*
  DescriptorType: Integer   // INT
): Pointer; stdcall;
  external 'WINUSB.dll' name 'WinUsb_ParseDescriptors';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WinUsb_ParseDescriptors"
  c_WinUsb_ParseDescriptors :: Ptr () -> Word32 -> Ptr () -> Int32 -> IO (Ptr ())
-- DescriptorBuffer : void* -> Ptr ()
-- TotalLength : DWORD -> Word32
-- StartPosition : void* -> Ptr ()
-- DescriptorType : INT -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let winusb_parsedescriptors =
  foreign "WinUsb_ParseDescriptors"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> int32_t @-> returning (ptr void))
(* DescriptorBuffer : void* -> (ptr void) *)
(* TotalLength : DWORD -> uint32_t *)
(* StartPosition : void* -> (ptr void) *)
(* DescriptorType : INT -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winusb (t "WINUSB.dll"))
(cffi:use-foreign-library winusb)

(cffi:defcfun ("WinUsb_ParseDescriptors" win-usb-parse-descriptors :convention :stdcall) :pointer
  (descriptor-buffer :pointer)   ; void*
  (total-length :uint32)   ; DWORD
  (start-position :pointer)   ; void*
  (descriptor-type :int32))   ; INT
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WinUsb_ParseDescriptors = Win32::API::More->new('WINUSB',
    'LPVOID WinUsb_ParseDescriptors(LPVOID DescriptorBuffer, DWORD TotalLength, LPVOID StartPosition, int DescriptorType)');
# my $ret = $WinUsb_ParseDescriptors->Call($DescriptorBuffer, $TotalLength, $StartPosition, $DescriptorType);
# DescriptorBuffer : void* -> LPVOID
# TotalLength : DWORD -> DWORD
# StartPosition : void* -> LPVOID
# DescriptorType : INT -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型