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

CreateDeviceAccessInstance

関数
デバイスインターフェースへの非同期アクセスインスタンスを作成する。
DLLdeviceaccess.dll呼出規約winapi

シグネチャ

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

HRESULT CreateDeviceAccessInstance(
    LPCWSTR deviceInterfacePath,
    DWORD desiredAccess,
    ICreateDeviceAccessAsync** createAsync
);

パラメーター

名前方向説明
deviceInterfacePathLPCWSTRinアクセス対象のデバイスインターフェイスパス(Unicode)。
desiredAccessDWORDin要求するアクセス権を示すフラグ。読み取り/書き込みを指定する。
createAsyncICreateDeviceAccessAsync**out非同期にアクセスを開くためのICreateDeviceAccessAsyncインターフェイスを受け取る出力ポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT CreateDeviceAccessInstance(
    LPCWSTR deviceInterfacePath,
    DWORD desiredAccess,
    ICreateDeviceAccessAsync** createAsync
);
[DllImport("deviceaccess.dll", ExactSpelling = true)]
static extern int CreateDeviceAccessInstance(
    [MarshalAs(UnmanagedType.LPWStr)] string deviceInterfacePath,   // LPCWSTR
    uint desiredAccess,   // DWORD
    IntPtr createAsync   // ICreateDeviceAccessAsync** out
);
<DllImport("deviceaccess.dll", ExactSpelling:=True)>
Public Shared Function CreateDeviceAccessInstance(
    <MarshalAs(UnmanagedType.LPWStr)> deviceInterfacePath As String,   ' LPCWSTR
    desiredAccess As UInteger,   ' DWORD
    createAsync As IntPtr   ' ICreateDeviceAccessAsync** out
) As Integer
End Function
' deviceInterfacePath : LPCWSTR
' desiredAccess : DWORD
' createAsync : ICreateDeviceAccessAsync** out
Declare PtrSafe Function CreateDeviceAccessInstance Lib "deviceaccess" ( _
    ByVal deviceInterfacePath As LongPtr, _
    ByVal desiredAccess As Long, _
    ByVal createAsync As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateDeviceAccessInstance = ctypes.windll.deviceaccess.CreateDeviceAccessInstance
CreateDeviceAccessInstance.restype = ctypes.c_int
CreateDeviceAccessInstance.argtypes = [
    wintypes.LPCWSTR,  # deviceInterfacePath : LPCWSTR
    wintypes.DWORD,  # desiredAccess : DWORD
    ctypes.c_void_p,  # createAsync : ICreateDeviceAccessAsync** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('deviceaccess.dll')
CreateDeviceAccessInstance = Fiddle::Function.new(
  lib['CreateDeviceAccessInstance'],
  [
    Fiddle::TYPE_VOIDP,  # deviceInterfacePath : LPCWSTR
    -Fiddle::TYPE_INT,  # desiredAccess : DWORD
    Fiddle::TYPE_VOIDP,  # createAsync : ICreateDeviceAccessAsync** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "deviceaccess")]
extern "system" {
    fn CreateDeviceAccessInstance(
        deviceInterfacePath: *const u16,  // LPCWSTR
        desiredAccess: u32,  // DWORD
        createAsync: *mut *mut core::ffi::c_void  // ICreateDeviceAccessAsync** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("deviceaccess.dll")]
public static extern int CreateDeviceAccessInstance([MarshalAs(UnmanagedType.LPWStr)] string deviceInterfacePath, uint desiredAccess, IntPtr createAsync);
"@
$api = Add-Type -MemberDefinition $sig -Name 'deviceaccess_CreateDeviceAccessInstance' -Namespace Win32 -PassThru
# $api::CreateDeviceAccessInstance(deviceInterfacePath, desiredAccess, createAsync)
#uselib "deviceaccess.dll"
#func global CreateDeviceAccessInstance "CreateDeviceAccessInstance" sptr, sptr, sptr
; CreateDeviceAccessInstance deviceInterfacePath, desiredAccess, createAsync   ; 戻り値は stat
; deviceInterfacePath : LPCWSTR -> "sptr"
; desiredAccess : DWORD -> "sptr"
; createAsync : ICreateDeviceAccessAsync** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "deviceaccess.dll"
#cfunc global CreateDeviceAccessInstance "CreateDeviceAccessInstance" wstr, int, sptr
; res = CreateDeviceAccessInstance(deviceInterfacePath, desiredAccess, createAsync)
; deviceInterfacePath : LPCWSTR -> "wstr"
; desiredAccess : DWORD -> "int"
; createAsync : ICreateDeviceAccessAsync** out -> "sptr"
; HRESULT CreateDeviceAccessInstance(LPCWSTR deviceInterfacePath, DWORD desiredAccess, ICreateDeviceAccessAsync** createAsync)
#uselib "deviceaccess.dll"
#cfunc global CreateDeviceAccessInstance "CreateDeviceAccessInstance" wstr, int, intptr
; res = CreateDeviceAccessInstance(deviceInterfacePath, desiredAccess, createAsync)
; deviceInterfacePath : LPCWSTR -> "wstr"
; desiredAccess : DWORD -> "int"
; createAsync : ICreateDeviceAccessAsync** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	deviceaccess = windows.NewLazySystemDLL("deviceaccess.dll")
	procCreateDeviceAccessInstance = deviceaccess.NewProc("CreateDeviceAccessInstance")
)

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

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

typedef CreateDeviceAccessInstanceNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>);
typedef CreateDeviceAccessInstanceDart = int Function(Pointer<Utf16>, int, Pointer<Void>);
final CreateDeviceAccessInstance = DynamicLibrary.open('deviceaccess.dll')
    .lookupFunction<CreateDeviceAccessInstanceNative, CreateDeviceAccessInstanceDart>('CreateDeviceAccessInstance');
// deviceInterfacePath : LPCWSTR -> Pointer<Utf16>
// desiredAccess : DWORD -> Uint32
// createAsync : ICreateDeviceAccessAsync** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateDeviceAccessInstance(
  deviceInterfacePath: PWideChar;   // LPCWSTR
  desiredAccess: DWORD;   // DWORD
  createAsync: Pointer   // ICreateDeviceAccessAsync** out
): Integer; stdcall;
  external 'deviceaccess.dll' name 'CreateDeviceAccessInstance';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateDeviceAccessInstance"
  c_CreateDeviceAccessInstance :: CWString -> Word32 -> Ptr () -> IO Int32
-- deviceInterfacePath : LPCWSTR -> CWString
-- desiredAccess : DWORD -> Word32
-- createAsync : ICreateDeviceAccessAsync** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createdeviceaccessinstance =
  foreign "CreateDeviceAccessInstance"
    ((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* deviceInterfacePath : LPCWSTR -> (ptr uint16_t) *)
(* desiredAccess : DWORD -> uint32_t *)
(* createAsync : ICreateDeviceAccessAsync** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library deviceaccess (t "deviceaccess.dll"))
(cffi:use-foreign-library deviceaccess)

(cffi:defcfun ("CreateDeviceAccessInstance" create-device-access-instance :convention :stdcall) :int32
  (device-interface-path (:string :encoding :utf-16le))   ; LPCWSTR
  (desired-access :uint32)   ; DWORD
  (create-async :pointer))   ; ICreateDeviceAccessAsync** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateDeviceAccessInstance = Win32::API::More->new('deviceaccess',
    'int CreateDeviceAccessInstance(LPCWSTR deviceInterfacePath, DWORD desiredAccess, LPVOID createAsync)');
# my $ret = $CreateDeviceAccessInstance->Call($deviceInterfacePath, $desiredAccess, $createAsync);
# deviceInterfacePath : LPCWSTR -> LPCWSTR
# desiredAccess : DWORD -> DWORD
# createAsync : ICreateDeviceAccessAsync** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型