Win32 API 日本語リファレンス
ホームDevices.Enumeration.Pnp › SwDeviceInterfacePropertySet

SwDeviceInterfacePropertySet

関数
ソフトウェアデバイスのインターフェイスのプロパティを設定する。
DLLCFGMGR32.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT SwDeviceInterfacePropertySet(
    HSWDEVICE hSwDevice,
    LPCWSTR pszDeviceInterfaceId,
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties
);

パラメーター

名前方向説明
hSwDeviceHSWDEVICEin対象のソフトウェアデバイスハンドルを指定する。
pszDeviceInterfaceIdLPCWSTRinプロパティを設定する対象のデバイスインターフェイスID文字列を指定する。
cPropertyCountDWORDinpProperties配列が含むプロパティ数を指定する。
pPropertiesDEVPROPERTY*inインターフェイスに設定するDEVPROPERTY配列へのポインタを指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SwDeviceInterfacePropertySet(
    HSWDEVICE hSwDevice,
    LPCWSTR pszDeviceInterfaceId,
    DWORD cPropertyCount,
    const DEVPROPERTY* pProperties
);
[DllImport("CFGMGR32.dll", ExactSpelling = true)]
static extern int SwDeviceInterfacePropertySet(
    IntPtr hSwDevice,   // HSWDEVICE
    [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceInterfaceId,   // LPCWSTR
    uint cPropertyCount,   // DWORD
    IntPtr pProperties   // DEVPROPERTY*
);
<DllImport("CFGMGR32.dll", ExactSpelling:=True)>
Public Shared Function SwDeviceInterfacePropertySet(
    hSwDevice As IntPtr,   ' HSWDEVICE
    <MarshalAs(UnmanagedType.LPWStr)> pszDeviceInterfaceId As String,   ' LPCWSTR
    cPropertyCount As UInteger,   ' DWORD
    pProperties As IntPtr   ' DEVPROPERTY*
) As Integer
End Function
' hSwDevice : HSWDEVICE
' pszDeviceInterfaceId : LPCWSTR
' cPropertyCount : DWORD
' pProperties : DEVPROPERTY*
Declare PtrSafe Function SwDeviceInterfacePropertySet Lib "cfgmgr32" ( _
    ByVal hSwDevice As LongPtr, _
    ByVal pszDeviceInterfaceId As LongPtr, _
    ByVal cPropertyCount As Long, _
    ByVal pProperties As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SwDeviceInterfacePropertySet = ctypes.windll.cfgmgr32.SwDeviceInterfacePropertySet
SwDeviceInterfacePropertySet.restype = ctypes.c_int
SwDeviceInterfacePropertySet.argtypes = [
    wintypes.HANDLE,  # hSwDevice : HSWDEVICE
    wintypes.LPCWSTR,  # pszDeviceInterfaceId : LPCWSTR
    wintypes.DWORD,  # cPropertyCount : DWORD
    ctypes.c_void_p,  # pProperties : DEVPROPERTY*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CFGMGR32.dll')
SwDeviceInterfacePropertySet = Fiddle::Function.new(
  lib['SwDeviceInterfacePropertySet'],
  [
    Fiddle::TYPE_VOIDP,  # hSwDevice : HSWDEVICE
    Fiddle::TYPE_VOIDP,  # pszDeviceInterfaceId : LPCWSTR
    -Fiddle::TYPE_INT,  # cPropertyCount : DWORD
    Fiddle::TYPE_VOIDP,  # pProperties : DEVPROPERTY*
  ],
  Fiddle::TYPE_INT)
#[link(name = "cfgmgr32")]
extern "system" {
    fn SwDeviceInterfacePropertySet(
        hSwDevice: *mut core::ffi::c_void,  // HSWDEVICE
        pszDeviceInterfaceId: *const u16,  // LPCWSTR
        cPropertyCount: u32,  // DWORD
        pProperties: *const DEVPROPERTY  // DEVPROPERTY*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CFGMGR32.dll")]
public static extern int SwDeviceInterfacePropertySet(IntPtr hSwDevice, [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceInterfaceId, uint cPropertyCount, IntPtr pProperties);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CFGMGR32_SwDeviceInterfacePropertySet' -Namespace Win32 -PassThru
# $api::SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
#uselib "CFGMGR32.dll"
#func global SwDeviceInterfacePropertySet "SwDeviceInterfacePropertySet" sptr, sptr, sptr, sptr
; SwDeviceInterfacePropertySet hSwDevice, pszDeviceInterfaceId, cPropertyCount, varptr(pProperties)   ; 戻り値は stat
; hSwDevice : HSWDEVICE -> "sptr"
; pszDeviceInterfaceId : LPCWSTR -> "sptr"
; cPropertyCount : DWORD -> "sptr"
; pProperties : DEVPROPERTY* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfacePropertySet "SwDeviceInterfacePropertySet" sptr, wstr, int, var
; res = SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
; hSwDevice : HSWDEVICE -> "sptr"
; pszDeviceInterfaceId : LPCWSTR -> "wstr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT SwDeviceInterfacePropertySet(HSWDEVICE hSwDevice, LPCWSTR pszDeviceInterfaceId, DWORD cPropertyCount, DEVPROPERTY* pProperties)
#uselib "CFGMGR32.dll"
#cfunc global SwDeviceInterfacePropertySet "SwDeviceInterfacePropertySet" intptr, wstr, int, var
; res = SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
; hSwDevice : HSWDEVICE -> "intptr"
; pszDeviceInterfaceId : LPCWSTR -> "wstr"
; cPropertyCount : DWORD -> "int"
; pProperties : DEVPROPERTY* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cfgmgr32 = windows.NewLazySystemDLL("CFGMGR32.dll")
	procSwDeviceInterfacePropertySet = cfgmgr32.NewProc("SwDeviceInterfacePropertySet")
)

// hSwDevice (HSWDEVICE), pszDeviceInterfaceId (LPCWSTR), cPropertyCount (DWORD), pProperties (DEVPROPERTY*)
r1, _, err := procSwDeviceInterfacePropertySet.Call(
	uintptr(hSwDevice),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszDeviceInterfaceId))),
	uintptr(cPropertyCount),
	uintptr(pProperties),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SwDeviceInterfacePropertySet(
  hSwDevice: THandle;   // HSWDEVICE
  pszDeviceInterfaceId: PWideChar;   // LPCWSTR
  cPropertyCount: DWORD;   // DWORD
  pProperties: Pointer   // DEVPROPERTY*
): Integer; stdcall;
  external 'CFGMGR32.dll' name 'SwDeviceInterfacePropertySet';
result := DllCall("CFGMGR32\SwDeviceInterfacePropertySet"
    , "Ptr", hSwDevice   ; HSWDEVICE
    , "WStr", pszDeviceInterfaceId   ; LPCWSTR
    , "UInt", cPropertyCount   ; DWORD
    , "Ptr", pProperties   ; DEVPROPERTY*
    , "Int")   ; return: HRESULT
●SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties) = DLL("CFGMGR32.dll", "int SwDeviceInterfacePropertySet(void*, char*, dword, void*)")
# 呼び出し: SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
# hSwDevice : HSWDEVICE -> "void*"
# pszDeviceInterfaceId : LPCWSTR -> "char*"
# cPropertyCount : DWORD -> "dword"
# pProperties : DEVPROPERTY* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "cfgmgr32" fn SwDeviceInterfacePropertySet(
    hSwDevice: ?*anyopaque, // HSWDEVICE
    pszDeviceInterfaceId: [*c]const u16, // LPCWSTR
    cPropertyCount: u32, // DWORD
    pProperties: [*c]DEVPROPERTY // DEVPROPERTY*
) callconv(std.os.windows.WINAPI) i32;
proc SwDeviceInterfacePropertySet(
    hSwDevice: pointer,  # HSWDEVICE
    pszDeviceInterfaceId: WideCString,  # LPCWSTR
    cPropertyCount: uint32,  # DWORD
    pProperties: ptr DEVPROPERTY  # DEVPROPERTY*
): int32 {.importc: "SwDeviceInterfacePropertySet", stdcall, dynlib: "CFGMGR32.dll".}
pragma(lib, "cfgmgr32");
extern(Windows)
int SwDeviceInterfacePropertySet(
    void* hSwDevice,   // HSWDEVICE
    const(wchar)* pszDeviceInterfaceId,   // LPCWSTR
    uint cPropertyCount,   // DWORD
    DEVPROPERTY* pProperties   // DEVPROPERTY*
);
ccall((:SwDeviceInterfacePropertySet, "CFGMGR32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cwstring, UInt32, Ptr{DEVPROPERTY}),
      hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
# hSwDevice : HSWDEVICE -> Ptr{Cvoid}
# pszDeviceInterfaceId : LPCWSTR -> Cwstring
# cPropertyCount : DWORD -> UInt32
# pProperties : DEVPROPERTY* -> Ptr{DEVPROPERTY}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SwDeviceInterfacePropertySet(
    void* hSwDevice,
    const uint16_t* pszDeviceInterfaceId,
    uint32_t cPropertyCount,
    void* pProperties);
]]
local cfgmgr32 = ffi.load("cfgmgr32")
-- cfgmgr32.SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
-- hSwDevice : HSWDEVICE
-- pszDeviceInterfaceId : LPCWSTR
-- cPropertyCount : DWORD
-- pProperties : DEVPROPERTY*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CFGMGR32.dll');
const SwDeviceInterfacePropertySet = lib.func('__stdcall', 'SwDeviceInterfacePropertySet', 'int32_t', ['void *', 'str16', 'uint32_t', 'void *']);
// SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
// hSwDevice : HSWDEVICE -> 'void *'
// pszDeviceInterfaceId : LPCWSTR -> 'str16'
// cPropertyCount : DWORD -> 'uint32_t'
// pProperties : DEVPROPERTY* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CFGMGR32.dll", {
  SwDeviceInterfacePropertySet: { parameters: ["pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties)
// hSwDevice : HSWDEVICE -> "pointer"
// pszDeviceInterfaceId : LPCWSTR -> "buffer"
// cPropertyCount : DWORD -> "u32"
// pProperties : DEVPROPERTY* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SwDeviceInterfacePropertySet(
    void* hSwDevice,
    const uint16_t* pszDeviceInterfaceId,
    uint32_t cPropertyCount,
    void* pProperties);
C, "CFGMGR32.dll");
// $ffi->SwDeviceInterfacePropertySet(hSwDevice, pszDeviceInterfaceId, cPropertyCount, pProperties);
// hSwDevice : HSWDEVICE
// pszDeviceInterfaceId : LPCWSTR
// cPropertyCount : DWORD
// pProperties : DEVPROPERTY*
// 構造体/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 Cfgmgr32 extends StdCallLibrary {
    Cfgmgr32 INSTANCE = Native.load("cfgmgr32", Cfgmgr32.class);
    int SwDeviceInterfacePropertySet(
        Pointer hSwDevice,   // HSWDEVICE
        WString pszDeviceInterfaceId,   // LPCWSTR
        int cPropertyCount,   // DWORD
        Pointer pProperties   // DEVPROPERTY*
    );
}
@[Link("cfgmgr32")]
lib LibCFGMGR32
  fun SwDeviceInterfacePropertySet = SwDeviceInterfacePropertySet(
    hSwDevice : Void*,   # HSWDEVICE
    pszDeviceInterfaceId : UInt16*,   # LPCWSTR
    cPropertyCount : UInt32,   # DWORD
    pProperties : DEVPROPERTY*   # DEVPROPERTY*
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SwDeviceInterfacePropertySetNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>);
typedef SwDeviceInterfacePropertySetDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>);
final SwDeviceInterfacePropertySet = DynamicLibrary.open('CFGMGR32.dll')
    .lookupFunction<SwDeviceInterfacePropertySetNative, SwDeviceInterfacePropertySetDart>('SwDeviceInterfacePropertySet');
// hSwDevice : HSWDEVICE -> Pointer<Void>
// pszDeviceInterfaceId : LPCWSTR -> Pointer<Utf16>
// cPropertyCount : DWORD -> Uint32
// pProperties : DEVPROPERTY* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SwDeviceInterfacePropertySet(
  hSwDevice: THandle;   // HSWDEVICE
  pszDeviceInterfaceId: PWideChar;   // LPCWSTR
  cPropertyCount: DWORD;   // DWORD
  pProperties: Pointer   // DEVPROPERTY*
): Integer; stdcall;
  external 'CFGMGR32.dll' name 'SwDeviceInterfacePropertySet';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SwDeviceInterfacePropertySet"
  c_SwDeviceInterfacePropertySet :: Ptr () -> CWString -> Word32 -> Ptr () -> IO Int32
-- hSwDevice : HSWDEVICE -> Ptr ()
-- pszDeviceInterfaceId : LPCWSTR -> CWString
-- cPropertyCount : DWORD -> Word32
-- pProperties : DEVPROPERTY* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let swdeviceinterfacepropertyset =
  foreign "SwDeviceInterfacePropertySet"
    ((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hSwDevice : HSWDEVICE -> (ptr void) *)
(* pszDeviceInterfaceId : LPCWSTR -> (ptr uint16_t) *)
(* cPropertyCount : DWORD -> uint32_t *)
(* pProperties : DEVPROPERTY* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library cfgmgr32 (t "CFGMGR32.dll"))
(cffi:use-foreign-library cfgmgr32)

(cffi:defcfun ("SwDeviceInterfacePropertySet" sw-device-interface-property-set :convention :stdcall) :int32
  (h-sw-device :pointer)   ; HSWDEVICE
  (psz-device-interface-id (:string :encoding :utf-16le))   ; LPCWSTR
  (c-property-count :uint32)   ; DWORD
  (p-properties :pointer))   ; DEVPROPERTY*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SwDeviceInterfacePropertySet = Win32::API::More->new('CFGMGR32',
    'int SwDeviceInterfacePropertySet(HANDLE hSwDevice, LPCWSTR pszDeviceInterfaceId, DWORD cPropertyCount, LPVOID pProperties)');
# my $ret = $SwDeviceInterfacePropertySet->Call($hSwDevice, $pszDeviceInterfaceId, $cPropertyCount, $pProperties);
# hSwDevice : HSWDEVICE -> HANDLE
# pszDeviceInterfaceId : LPCWSTR -> LPCWSTR
# cPropertyCount : DWORD -> DWORD
# pProperties : DEVPROPERTY* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型