ホーム › Media.KernelStreaming › KsSynchronousDeviceControl
KsSynchronousDeviceControl
関数KSデバイスへ同期的にIOコントロールを送信する。
シグネチャ
// ksproxy.ax
#include <windows.h>
HRESULT KsSynchronousDeviceControl(
HANDLE Handle,
DWORD IoControl,
void* InBuffer, // optional
DWORD InLength,
void* OutBuffer, // optional
DWORD OutLength,
DWORD* BytesReturned // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Handle | HANDLE | in | 制御要求を送るカーネルストリーミングオブジェクトのハンドル。 |
| IoControl | DWORD | in | 実行するI/O制御コード(IOCTL)。 |
| InBuffer | void* | inoptional | 入力データを格納したバッファへのポインター。不要ならNULL可。 |
| InLength | DWORD | in | InBufferのバイトサイズ。 |
| OutBuffer | void* | outoptional | 出力データを受け取るバッファへのポインター。不要ならNULL可。 |
| OutLength | DWORD | in | OutBufferのバイトサイズ。 |
| BytesReturned | DWORD* | inoutoptional | 実際に返されたバイト数を受け取るDWORDへのポインター。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// ksproxy.ax
#include <windows.h>
HRESULT KsSynchronousDeviceControl(
HANDLE Handle,
DWORD IoControl,
void* InBuffer, // optional
DWORD InLength,
void* OutBuffer, // optional
DWORD OutLength,
DWORD* BytesReturned // optional
);[DllImport("ksproxy.ax", ExactSpelling = true)]
static extern int KsSynchronousDeviceControl(
IntPtr Handle, // HANDLE
uint IoControl, // DWORD
IntPtr InBuffer, // void* optional
uint InLength, // DWORD
IntPtr OutBuffer, // void* optional, out
uint OutLength, // DWORD
IntPtr BytesReturned // DWORD* optional, in/out
);<DllImport("ksproxy.ax", ExactSpelling:=True)>
Public Shared Function KsSynchronousDeviceControl(
Handle As IntPtr, ' HANDLE
IoControl As UInteger, ' DWORD
InBuffer As IntPtr, ' void* optional
InLength As UInteger, ' DWORD
OutBuffer As IntPtr, ' void* optional, out
OutLength As UInteger, ' DWORD
BytesReturned As IntPtr ' DWORD* optional, in/out
) As Integer
End Function' Handle : HANDLE
' IoControl : DWORD
' InBuffer : void* optional
' InLength : DWORD
' OutBuffer : void* optional, out
' OutLength : DWORD
' BytesReturned : DWORD* optional, in/out
Declare PtrSafe Function KsSynchronousDeviceControl Lib "ksproxy.ax" ( _
ByVal Handle As LongPtr, _
ByVal IoControl As Long, _
ByVal InBuffer As LongPtr, _
ByVal InLength As Long, _
ByVal OutBuffer As LongPtr, _
ByVal OutLength As Long, _
ByVal BytesReturned As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
KsSynchronousDeviceControl = ctypes.windll.LoadLibrary("ksproxy.ax").KsSynchronousDeviceControl
KsSynchronousDeviceControl.restype = ctypes.c_int
KsSynchronousDeviceControl.argtypes = [
wintypes.HANDLE, # Handle : HANDLE
wintypes.DWORD, # IoControl : DWORD
ctypes.POINTER(None), # InBuffer : void* optional
wintypes.DWORD, # InLength : DWORD
ctypes.POINTER(None), # OutBuffer : void* optional, out
wintypes.DWORD, # OutLength : DWORD
ctypes.POINTER(wintypes.DWORD), # BytesReturned : DWORD* optional, in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ksproxy.ax')
KsSynchronousDeviceControl = Fiddle::Function.new(
lib['KsSynchronousDeviceControl'],
[
Fiddle::TYPE_VOIDP, # Handle : HANDLE
-Fiddle::TYPE_INT, # IoControl : DWORD
Fiddle::TYPE_VOIDP, # InBuffer : void* optional
-Fiddle::TYPE_INT, # InLength : DWORD
Fiddle::TYPE_VOIDP, # OutBuffer : void* optional, out
-Fiddle::TYPE_INT, # OutLength : DWORD
Fiddle::TYPE_VOIDP, # BytesReturned : DWORD* optional, in/out
],
Fiddle::TYPE_INT)#[link(name = "ksproxy.ax")]
extern "system" {
fn KsSynchronousDeviceControl(
Handle: *mut core::ffi::c_void, // HANDLE
IoControl: u32, // DWORD
InBuffer: *mut (), // void* optional
InLength: u32, // DWORD
OutBuffer: *mut (), // void* optional, out
OutLength: u32, // DWORD
BytesReturned: *mut u32 // DWORD* optional, in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ksproxy.ax")]
public static extern int KsSynchronousDeviceControl(IntPtr Handle, uint IoControl, IntPtr InBuffer, uint InLength, IntPtr OutBuffer, uint OutLength, IntPtr BytesReturned);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ksproxy.ax_KsSynchronousDeviceControl' -Namespace Win32 -PassThru
# $api::KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned)#uselib "ksproxy.ax"
#func global KsSynchronousDeviceControl "KsSynchronousDeviceControl" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; KsSynchronousDeviceControl Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, varptr(BytesReturned) ; 戻り値は stat
; Handle : HANDLE -> "sptr"
; IoControl : DWORD -> "sptr"
; InBuffer : void* optional -> "sptr"
; InLength : DWORD -> "sptr"
; OutBuffer : void* optional, out -> "sptr"
; OutLength : DWORD -> "sptr"
; BytesReturned : DWORD* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ksproxy.ax" #cfunc global KsSynchronousDeviceControl "KsSynchronousDeviceControl" sptr, int, sptr, int, sptr, int, var ; res = KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned) ; Handle : HANDLE -> "sptr" ; IoControl : DWORD -> "int" ; InBuffer : void* optional -> "sptr" ; InLength : DWORD -> "int" ; OutBuffer : void* optional, out -> "sptr" ; OutLength : DWORD -> "int" ; BytesReturned : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ksproxy.ax" #cfunc global KsSynchronousDeviceControl "KsSynchronousDeviceControl" sptr, int, sptr, int, sptr, int, sptr ; res = KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, varptr(BytesReturned)) ; Handle : HANDLE -> "sptr" ; IoControl : DWORD -> "int" ; InBuffer : void* optional -> "sptr" ; InLength : DWORD -> "int" ; OutBuffer : void* optional, out -> "sptr" ; OutLength : DWORD -> "int" ; BytesReturned : DWORD* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT KsSynchronousDeviceControl(HANDLE Handle, DWORD IoControl, void* InBuffer, DWORD InLength, void* OutBuffer, DWORD OutLength, DWORD* BytesReturned) #uselib "ksproxy.ax" #cfunc global KsSynchronousDeviceControl "KsSynchronousDeviceControl" intptr, int, intptr, int, intptr, int, var ; res = KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned) ; Handle : HANDLE -> "intptr" ; IoControl : DWORD -> "int" ; InBuffer : void* optional -> "intptr" ; InLength : DWORD -> "int" ; OutBuffer : void* optional, out -> "intptr" ; OutLength : DWORD -> "int" ; BytesReturned : DWORD* optional, in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT KsSynchronousDeviceControl(HANDLE Handle, DWORD IoControl, void* InBuffer, DWORD InLength, void* OutBuffer, DWORD OutLength, DWORD* BytesReturned) #uselib "ksproxy.ax" #cfunc global KsSynchronousDeviceControl "KsSynchronousDeviceControl" intptr, int, intptr, int, intptr, int, intptr ; res = KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, varptr(BytesReturned)) ; Handle : HANDLE -> "intptr" ; IoControl : DWORD -> "int" ; InBuffer : void* optional -> "intptr" ; InLength : DWORD -> "int" ; OutBuffer : void* optional, out -> "intptr" ; OutLength : DWORD -> "int" ; BytesReturned : DWORD* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ksproxy_ax = windows.NewLazySystemDLL("ksproxy.ax")
procKsSynchronousDeviceControl = ksproxy_ax.NewProc("KsSynchronousDeviceControl")
)
// Handle (HANDLE), IoControl (DWORD), InBuffer (void* optional), InLength (DWORD), OutBuffer (void* optional, out), OutLength (DWORD), BytesReturned (DWORD* optional, in/out)
r1, _, err := procKsSynchronousDeviceControl.Call(
uintptr(Handle),
uintptr(IoControl),
uintptr(InBuffer),
uintptr(InLength),
uintptr(OutBuffer),
uintptr(OutLength),
uintptr(BytesReturned),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction KsSynchronousDeviceControl(
Handle: THandle; // HANDLE
IoControl: DWORD; // DWORD
InBuffer: Pointer; // void* optional
InLength: DWORD; // DWORD
OutBuffer: Pointer; // void* optional, out
OutLength: DWORD; // DWORD
BytesReturned: Pointer // DWORD* optional, in/out
): Integer; stdcall;
external 'ksproxy.ax' name 'KsSynchronousDeviceControl';result := DllCall("ksproxy.ax\KsSynchronousDeviceControl"
, "Ptr", Handle ; HANDLE
, "UInt", IoControl ; DWORD
, "Ptr", InBuffer ; void* optional
, "UInt", InLength ; DWORD
, "Ptr", OutBuffer ; void* optional, out
, "UInt", OutLength ; DWORD
, "Ptr", BytesReturned ; DWORD* optional, in/out
, "Int") ; return: HRESULT●KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned) = DLL("ksproxy.ax", "int KsSynchronousDeviceControl(void*, dword, void*, dword, void*, dword, void*)")
# 呼び出し: KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned)
# Handle : HANDLE -> "void*"
# IoControl : DWORD -> "dword"
# InBuffer : void* optional -> "void*"
# InLength : DWORD -> "dword"
# OutBuffer : void* optional, out -> "void*"
# OutLength : DWORD -> "dword"
# BytesReturned : DWORD* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ksproxy.ax" fn KsSynchronousDeviceControl(
Handle: ?*anyopaque, // HANDLE
IoControl: u32, // DWORD
InBuffer: ?*anyopaque, // void* optional
InLength: u32, // DWORD
OutBuffer: ?*anyopaque, // void* optional, out
OutLength: u32, // DWORD
BytesReturned: [*c]u32 // DWORD* optional, in/out
) callconv(std.os.windows.WINAPI) i32;proc KsSynchronousDeviceControl(
Handle: pointer, # HANDLE
IoControl: uint32, # DWORD
InBuffer: pointer, # void* optional
InLength: uint32, # DWORD
OutBuffer: pointer, # void* optional, out
OutLength: uint32, # DWORD
BytesReturned: ptr uint32 # DWORD* optional, in/out
): int32 {.importc: "KsSynchronousDeviceControl", stdcall, dynlib: "ksproxy.ax".}pragma(lib, "ksproxy.ax");
extern(Windows)
int KsSynchronousDeviceControl(
void* Handle, // HANDLE
uint IoControl, // DWORD
void* InBuffer, // void* optional
uint InLength, // DWORD
void* OutBuffer, // void* optional, out
uint OutLength, // DWORD
uint* BytesReturned // DWORD* optional, in/out
);ccall((:KsSynchronousDeviceControl, "ksproxy.ax"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}, UInt32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned)
# Handle : HANDLE -> Ptr{Cvoid}
# IoControl : DWORD -> UInt32
# InBuffer : void* optional -> Ptr{Cvoid}
# InLength : DWORD -> UInt32
# OutBuffer : void* optional, out -> Ptr{Cvoid}
# OutLength : DWORD -> UInt32
# BytesReturned : DWORD* optional, in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t KsSynchronousDeviceControl(
void* Handle,
uint32_t IoControl,
void* InBuffer,
uint32_t InLength,
void* OutBuffer,
uint32_t OutLength,
uint32_t* BytesReturned);
]]
local ksproxy.ax = ffi.load("ksproxy.ax")
-- ksproxy.ax.KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned)
-- Handle : HANDLE
-- IoControl : DWORD
-- InBuffer : void* optional
-- InLength : DWORD
-- OutBuffer : void* optional, out
-- OutLength : DWORD
-- BytesReturned : DWORD* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ksproxy.ax');
const KsSynchronousDeviceControl = lib.func('__stdcall', 'KsSynchronousDeviceControl', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t', 'void *', 'uint32_t', 'uint32_t *']);
// KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned)
// Handle : HANDLE -> 'void *'
// IoControl : DWORD -> 'uint32_t'
// InBuffer : void* optional -> 'void *'
// InLength : DWORD -> 'uint32_t'
// OutBuffer : void* optional, out -> 'void *'
// OutLength : DWORD -> 'uint32_t'
// BytesReturned : DWORD* optional, in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ksproxy.ax", {
KsSynchronousDeviceControl: { parameters: ["pointer", "u32", "pointer", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned)
// Handle : HANDLE -> "pointer"
// IoControl : DWORD -> "u32"
// InBuffer : void* optional -> "pointer"
// InLength : DWORD -> "u32"
// OutBuffer : void* optional, out -> "pointer"
// OutLength : DWORD -> "u32"
// BytesReturned : DWORD* optional, in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t KsSynchronousDeviceControl(
void* Handle,
uint32_t IoControl,
void* InBuffer,
uint32_t InLength,
void* OutBuffer,
uint32_t OutLength,
uint32_t* BytesReturned);
C, "ksproxy.ax");
// $ffi->KsSynchronousDeviceControl(Handle, IoControl, InBuffer, InLength, OutBuffer, OutLength, BytesReturned);
// Handle : HANDLE
// IoControl : DWORD
// InBuffer : void* optional
// InLength : DWORD
// OutBuffer : void* optional, out
// OutLength : DWORD
// BytesReturned : DWORD* optional, in/out
// 構造体/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 Ksproxy.ax extends StdCallLibrary {
Ksproxy.ax INSTANCE = Native.load("ksproxy.ax", Ksproxy.ax.class);
int KsSynchronousDeviceControl(
Pointer Handle, // HANDLE
int IoControl, // DWORD
Pointer InBuffer, // void* optional
int InLength, // DWORD
Pointer OutBuffer, // void* optional, out
int OutLength, // DWORD
IntByReference BytesReturned // DWORD* optional, in/out
);
}@[Link("ksproxy.ax")]
lib Libksproxy.ax
fun KsSynchronousDeviceControl = KsSynchronousDeviceControl(
Handle : Void*, # HANDLE
IoControl : UInt32, # DWORD
InBuffer : Void*, # void* optional
InLength : UInt32, # DWORD
OutBuffer : Void*, # void* optional, out
OutLength : UInt32, # DWORD
BytesReturned : UInt32* # DWORD* optional, in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef KsSynchronousDeviceControlNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef KsSynchronousDeviceControlDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Void>, int, Pointer<Uint32>);
final KsSynchronousDeviceControl = DynamicLibrary.open('ksproxy.ax')
.lookupFunction<KsSynchronousDeviceControlNative, KsSynchronousDeviceControlDart>('KsSynchronousDeviceControl');
// Handle : HANDLE -> Pointer<Void>
// IoControl : DWORD -> Uint32
// InBuffer : void* optional -> Pointer<Void>
// InLength : DWORD -> Uint32
// OutBuffer : void* optional, out -> Pointer<Void>
// OutLength : DWORD -> Uint32
// BytesReturned : DWORD* optional, in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function KsSynchronousDeviceControl(
Handle: THandle; // HANDLE
IoControl: DWORD; // DWORD
InBuffer: Pointer; // void* optional
InLength: DWORD; // DWORD
OutBuffer: Pointer; // void* optional, out
OutLength: DWORD; // DWORD
BytesReturned: Pointer // DWORD* optional, in/out
): Integer; stdcall;
external 'ksproxy.ax' name 'KsSynchronousDeviceControl';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "KsSynchronousDeviceControl"
c_KsSynchronousDeviceControl :: Ptr () -> Word32 -> Ptr () -> Word32 -> Ptr () -> Word32 -> Ptr Word32 -> IO Int32
-- Handle : HANDLE -> Ptr ()
-- IoControl : DWORD -> Word32
-- InBuffer : void* optional -> Ptr ()
-- InLength : DWORD -> Word32
-- OutBuffer : void* optional, out -> Ptr ()
-- OutLength : DWORD -> Word32
-- BytesReturned : DWORD* optional, in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let kssynchronousdevicecontrol =
foreign "KsSynchronousDeviceControl"
((ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* Handle : HANDLE -> (ptr void) *)
(* IoControl : DWORD -> uint32_t *)
(* InBuffer : void* optional -> (ptr void) *)
(* InLength : DWORD -> uint32_t *)
(* OutBuffer : void* optional, out -> (ptr void) *)
(* OutLength : DWORD -> uint32_t *)
(* BytesReturned : DWORD* optional, in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ksproxy.ax (t "ksproxy.ax"))
(cffi:use-foreign-library ksproxy.ax)
(cffi:defcfun ("KsSynchronousDeviceControl" ks-synchronous-device-control :convention :stdcall) :int32
(handle :pointer) ; HANDLE
(io-control :uint32) ; DWORD
(in-buffer :pointer) ; void* optional
(in-length :uint32) ; DWORD
(out-buffer :pointer) ; void* optional, out
(out-length :uint32) ; DWORD
(bytes-returned :pointer)) ; DWORD* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $KsSynchronousDeviceControl = Win32::API::More->new('ksproxy.ax',
'int KsSynchronousDeviceControl(HANDLE Handle, DWORD IoControl, LPVOID InBuffer, DWORD InLength, LPVOID OutBuffer, DWORD OutLength, LPVOID BytesReturned)');
# my $ret = $KsSynchronousDeviceControl->Call($Handle, $IoControl, $InBuffer, $InLength, $OutBuffer, $OutLength, $BytesReturned);
# Handle : HANDLE -> HANDLE
# IoControl : DWORD -> DWORD
# InBuffer : void* optional -> LPVOID
# InLength : DWORD -> DWORD
# OutBuffer : void* optional, out -> LPVOID
# OutLength : DWORD -> DWORD
# BytesReturned : DWORD* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。