Win32 API 日本語リファレンス
ホームSystem.Hypervisor › WHvCreateVpciDevice

WHvCreateVpciDevice

関数
パーティションに仮想PCIデバイスを作成する。
DLLWinHvPlatform.dll呼出規約winapi

シグネチャ

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

HRESULT WHvCreateVpciDevice(
    WHV_PARTITION_HANDLE Partition,
    ULONGLONG LogicalDeviceId,
    HANDLE VpciResource,
    WHV_CREATE_VPCI_DEVICE_FLAGS Flags,
    HANDLE NotificationEventHandle   // optional
);

パラメーター

名前方向説明
PartitionWHV_PARTITION_HANDLEin対象パーティションのハンドルを指定する。
LogicalDeviceIdULONGLONGinデバイスを識別するために割り当てる論理デバイスIDを指定する。
VpciResourceHANDLEinWHvAllocateVpciResourceで取得したVPCIリソースのハンドルを指定する。
FlagsWHV_CREATE_VPCI_DEVICE_FLAGSinデバイス作成の動作を制御するフラグ列挙値を指定する。
NotificationEventHandleHANDLEinoptionalデバイス通知発生時にシグナルされるイベントハンドル。NULL可。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT WHvCreateVpciDevice(
    WHV_PARTITION_HANDLE Partition,
    ULONGLONG LogicalDeviceId,
    HANDLE VpciResource,
    WHV_CREATE_VPCI_DEVICE_FLAGS Flags,
    HANDLE NotificationEventHandle   // optional
);
[DllImport("WinHvPlatform.dll", ExactSpelling = true)]
static extern int WHvCreateVpciDevice(
    IntPtr Partition,   // WHV_PARTITION_HANDLE
    ulong LogicalDeviceId,   // ULONGLONG
    IntPtr VpciResource,   // HANDLE
    int Flags,   // WHV_CREATE_VPCI_DEVICE_FLAGS
    IntPtr NotificationEventHandle   // HANDLE optional
);
<DllImport("WinHvPlatform.dll", ExactSpelling:=True)>
Public Shared Function WHvCreateVpciDevice(
    Partition As IntPtr,   ' WHV_PARTITION_HANDLE
    LogicalDeviceId As ULong,   ' ULONGLONG
    VpciResource As IntPtr,   ' HANDLE
    Flags As Integer,   ' WHV_CREATE_VPCI_DEVICE_FLAGS
    NotificationEventHandle As IntPtr   ' HANDLE optional
) As Integer
End Function
' Partition : WHV_PARTITION_HANDLE
' LogicalDeviceId : ULONGLONG
' VpciResource : HANDLE
' Flags : WHV_CREATE_VPCI_DEVICE_FLAGS
' NotificationEventHandle : HANDLE optional
Declare PtrSafe Function WHvCreateVpciDevice Lib "winhvplatform" ( _
    ByVal Partition As LongPtr, _
    ByVal LogicalDeviceId As LongLong, _
    ByVal VpciResource As LongPtr, _
    ByVal Flags As Long, _
    ByVal NotificationEventHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WHvCreateVpciDevice = ctypes.windll.winhvplatform.WHvCreateVpciDevice
WHvCreateVpciDevice.restype = ctypes.c_int
WHvCreateVpciDevice.argtypes = [
    ctypes.c_ssize_t,  # Partition : WHV_PARTITION_HANDLE
    ctypes.c_ulonglong,  # LogicalDeviceId : ULONGLONG
    wintypes.HANDLE,  # VpciResource : HANDLE
    ctypes.c_int,  # Flags : WHV_CREATE_VPCI_DEVICE_FLAGS
    wintypes.HANDLE,  # NotificationEventHandle : HANDLE optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WinHvPlatform.dll')
WHvCreateVpciDevice = Fiddle::Function.new(
  lib['WHvCreateVpciDevice'],
  [
    Fiddle::TYPE_INTPTR_T,  # Partition : WHV_PARTITION_HANDLE
    -Fiddle::TYPE_LONG_LONG,  # LogicalDeviceId : ULONGLONG
    Fiddle::TYPE_VOIDP,  # VpciResource : HANDLE
    Fiddle::TYPE_INT,  # Flags : WHV_CREATE_VPCI_DEVICE_FLAGS
    Fiddle::TYPE_VOIDP,  # NotificationEventHandle : HANDLE optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "winhvplatform")]
extern "system" {
    fn WHvCreateVpciDevice(
        Partition: isize,  // WHV_PARTITION_HANDLE
        LogicalDeviceId: u64,  // ULONGLONG
        VpciResource: *mut core::ffi::c_void,  // HANDLE
        Flags: i32,  // WHV_CREATE_VPCI_DEVICE_FLAGS
        NotificationEventHandle: *mut core::ffi::c_void  // HANDLE optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WinHvPlatform.dll")]
public static extern int WHvCreateVpciDevice(IntPtr Partition, ulong LogicalDeviceId, IntPtr VpciResource, int Flags, IntPtr NotificationEventHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinHvPlatform_WHvCreateVpciDevice' -Namespace Win32 -PassThru
# $api::WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
#uselib "WinHvPlatform.dll"
#func global WHvCreateVpciDevice "WHvCreateVpciDevice" sptr, sptr, sptr, sptr, sptr
; WHvCreateVpciDevice Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle   ; 戻り値は stat
; Partition : WHV_PARTITION_HANDLE -> "sptr"
; LogicalDeviceId : ULONGLONG -> "sptr"
; VpciResource : HANDLE -> "sptr"
; Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> "sptr"
; NotificationEventHandle : HANDLE optional -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WinHvPlatform.dll"
#cfunc global WHvCreateVpciDevice "WHvCreateVpciDevice" sptr, int64, sptr, int, sptr
; res = WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
; Partition : WHV_PARTITION_HANDLE -> "sptr"
; LogicalDeviceId : ULONGLONG -> "int64"
; VpciResource : HANDLE -> "sptr"
; Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> "int"
; NotificationEventHandle : HANDLE optional -> "sptr"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; HRESULT WHvCreateVpciDevice(WHV_PARTITION_HANDLE Partition, ULONGLONG LogicalDeviceId, HANDLE VpciResource, WHV_CREATE_VPCI_DEVICE_FLAGS Flags, HANDLE NotificationEventHandle)
#uselib "WinHvPlatform.dll"
#cfunc global WHvCreateVpciDevice "WHvCreateVpciDevice" intptr, int64, intptr, int, intptr
; res = WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
; Partition : WHV_PARTITION_HANDLE -> "intptr"
; LogicalDeviceId : ULONGLONG -> "int64"
; VpciResource : HANDLE -> "intptr"
; Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> "int"
; NotificationEventHandle : HANDLE optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhvplatform = windows.NewLazySystemDLL("WinHvPlatform.dll")
	procWHvCreateVpciDevice = winhvplatform.NewProc("WHvCreateVpciDevice")
)

// Partition (WHV_PARTITION_HANDLE), LogicalDeviceId (ULONGLONG), VpciResource (HANDLE), Flags (WHV_CREATE_VPCI_DEVICE_FLAGS), NotificationEventHandle (HANDLE optional)
r1, _, err := procWHvCreateVpciDevice.Call(
	uintptr(Partition),
	uintptr(LogicalDeviceId),
	uintptr(VpciResource),
	uintptr(Flags),
	uintptr(NotificationEventHandle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WHvCreateVpciDevice(
  Partition: NativeInt;   // WHV_PARTITION_HANDLE
  LogicalDeviceId: UInt64;   // ULONGLONG
  VpciResource: THandle;   // HANDLE
  Flags: Integer;   // WHV_CREATE_VPCI_DEVICE_FLAGS
  NotificationEventHandle: THandle   // HANDLE optional
): Integer; stdcall;
  external 'WinHvPlatform.dll' name 'WHvCreateVpciDevice';
result := DllCall("WinHvPlatform\WHvCreateVpciDevice"
    , "Ptr", Partition   ; WHV_PARTITION_HANDLE
    , "Int64", LogicalDeviceId   ; ULONGLONG
    , "Ptr", VpciResource   ; HANDLE
    , "Int", Flags   ; WHV_CREATE_VPCI_DEVICE_FLAGS
    , "Ptr", NotificationEventHandle   ; HANDLE optional
    , "Int")   ; return: HRESULT
●WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle) = DLL("WinHvPlatform.dll", "int WHvCreateVpciDevice(int, qword, void*, int, void*)")
# 呼び出し: WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
# Partition : WHV_PARTITION_HANDLE -> "int"
# LogicalDeviceId : ULONGLONG -> "qword"
# VpciResource : HANDLE -> "void*"
# Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> "int"
# NotificationEventHandle : HANDLE optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winhvplatform" fn WHvCreateVpciDevice(
    Partition: isize, // WHV_PARTITION_HANDLE
    LogicalDeviceId: u64, // ULONGLONG
    VpciResource: ?*anyopaque, // HANDLE
    Flags: i32, // WHV_CREATE_VPCI_DEVICE_FLAGS
    NotificationEventHandle: ?*anyopaque // HANDLE optional
) callconv(std.os.windows.WINAPI) i32;
proc WHvCreateVpciDevice(
    Partition: int,  # WHV_PARTITION_HANDLE
    LogicalDeviceId: uint64,  # ULONGLONG
    VpciResource: pointer,  # HANDLE
    Flags: int32,  # WHV_CREATE_VPCI_DEVICE_FLAGS
    NotificationEventHandle: pointer  # HANDLE optional
): int32 {.importc: "WHvCreateVpciDevice", stdcall, dynlib: "WinHvPlatform.dll".}
pragma(lib, "winhvplatform");
extern(Windows)
int WHvCreateVpciDevice(
    ptrdiff_t Partition,   // WHV_PARTITION_HANDLE
    ulong LogicalDeviceId,   // ULONGLONG
    void* VpciResource,   // HANDLE
    int Flags,   // WHV_CREATE_VPCI_DEVICE_FLAGS
    void* NotificationEventHandle   // HANDLE optional
);
ccall((:WHvCreateVpciDevice, "WinHvPlatform.dll"), stdcall, Int32,
      (Int, UInt64, Ptr{Cvoid}, Int32, Ptr{Cvoid}),
      Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
# Partition : WHV_PARTITION_HANDLE -> Int
# LogicalDeviceId : ULONGLONG -> UInt64
# VpciResource : HANDLE -> Ptr{Cvoid}
# Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> Int32
# NotificationEventHandle : HANDLE optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WHvCreateVpciDevice(
    intptr_t Partition,
    uint64_t LogicalDeviceId,
    void* VpciResource,
    int32_t Flags,
    void* NotificationEventHandle);
]]
local winhvplatform = ffi.load("winhvplatform")
-- winhvplatform.WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
-- Partition : WHV_PARTITION_HANDLE
-- LogicalDeviceId : ULONGLONG
-- VpciResource : HANDLE
-- Flags : WHV_CREATE_VPCI_DEVICE_FLAGS
-- NotificationEventHandle : HANDLE optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WinHvPlatform.dll');
const WHvCreateVpciDevice = lib.func('__stdcall', 'WHvCreateVpciDevice', 'int32_t', ['intptr_t', 'uint64_t', 'void *', 'int32_t', 'void *']);
// WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
// Partition : WHV_PARTITION_HANDLE -> 'intptr_t'
// LogicalDeviceId : ULONGLONG -> 'uint64_t'
// VpciResource : HANDLE -> 'void *'
// Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> 'int32_t'
// NotificationEventHandle : HANDLE optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WinHvPlatform.dll", {
  WHvCreateVpciDevice: { parameters: ["isize", "u64", "pointer", "i32", "pointer"], result: "i32" },
});
// lib.symbols.WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle)
// Partition : WHV_PARTITION_HANDLE -> "isize"
// LogicalDeviceId : ULONGLONG -> "u64"
// VpciResource : HANDLE -> "pointer"
// Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> "i32"
// NotificationEventHandle : HANDLE optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WHvCreateVpciDevice(
    intptr_t Partition,
    uint64_t LogicalDeviceId,
    void* VpciResource,
    int32_t Flags,
    void* NotificationEventHandle);
C, "WinHvPlatform.dll");
// $ffi->WHvCreateVpciDevice(Partition, LogicalDeviceId, VpciResource, Flags, NotificationEventHandle);
// Partition : WHV_PARTITION_HANDLE
// LogicalDeviceId : ULONGLONG
// VpciResource : HANDLE
// Flags : WHV_CREATE_VPCI_DEVICE_FLAGS
// NotificationEventHandle : HANDLE optional
// 構造体/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 Winhvplatform extends StdCallLibrary {
    Winhvplatform INSTANCE = Native.load("winhvplatform", Winhvplatform.class);
    int WHvCreateVpciDevice(
        long Partition,   // WHV_PARTITION_HANDLE
        long LogicalDeviceId,   // ULONGLONG
        Pointer VpciResource,   // HANDLE
        int Flags,   // WHV_CREATE_VPCI_DEVICE_FLAGS
        Pointer NotificationEventHandle   // HANDLE optional
    );
}
@[Link("winhvplatform")]
lib LibWinHvPlatform
  fun WHvCreateVpciDevice = WHvCreateVpciDevice(
    Partition : LibC::SSizeT,   # WHV_PARTITION_HANDLE
    LogicalDeviceId : UInt64,   # ULONGLONG
    VpciResource : Void*,   # HANDLE
    Flags : Int32,   # WHV_CREATE_VPCI_DEVICE_FLAGS
    NotificationEventHandle : Void*   # HANDLE optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WHvCreateVpciDeviceNative = Int32 Function(IntPtr, Uint64, Pointer<Void>, Int32, Pointer<Void>);
typedef WHvCreateVpciDeviceDart = int Function(int, int, Pointer<Void>, int, Pointer<Void>);
final WHvCreateVpciDevice = DynamicLibrary.open('WinHvPlatform.dll')
    .lookupFunction<WHvCreateVpciDeviceNative, WHvCreateVpciDeviceDart>('WHvCreateVpciDevice');
// Partition : WHV_PARTITION_HANDLE -> IntPtr
// LogicalDeviceId : ULONGLONG -> Uint64
// VpciResource : HANDLE -> Pointer<Void>
// Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> Int32
// NotificationEventHandle : HANDLE optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WHvCreateVpciDevice(
  Partition: NativeInt;   // WHV_PARTITION_HANDLE
  LogicalDeviceId: UInt64;   // ULONGLONG
  VpciResource: THandle;   // HANDLE
  Flags: Integer;   // WHV_CREATE_VPCI_DEVICE_FLAGS
  NotificationEventHandle: THandle   // HANDLE optional
): Integer; stdcall;
  external 'WinHvPlatform.dll' name 'WHvCreateVpciDevice';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WHvCreateVpciDevice"
  c_WHvCreateVpciDevice :: CIntPtr -> Word64 -> Ptr () -> Int32 -> Ptr () -> IO Int32
-- Partition : WHV_PARTITION_HANDLE -> CIntPtr
-- LogicalDeviceId : ULONGLONG -> Word64
-- VpciResource : HANDLE -> Ptr ()
-- Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> Int32
-- NotificationEventHandle : HANDLE optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let whvcreatevpcidevice =
  foreign "WHvCreateVpciDevice"
    (intptr_t @-> uint64_t @-> (ptr void) @-> int32_t @-> (ptr void) @-> returning int32_t)
(* Partition : WHV_PARTITION_HANDLE -> intptr_t *)
(* LogicalDeviceId : ULONGLONG -> uint64_t *)
(* VpciResource : HANDLE -> (ptr void) *)
(* Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> int32_t *)
(* NotificationEventHandle : HANDLE optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winhvplatform (t "WinHvPlatform.dll"))
(cffi:use-foreign-library winhvplatform)

(cffi:defcfun ("WHvCreateVpciDevice" whv-create-vpci-device :convention :stdcall) :int32
  (partition :int64)   ; WHV_PARTITION_HANDLE
  (logical-device-id :uint64)   ; ULONGLONG
  (vpci-resource :pointer)   ; HANDLE
  (flags :int32)   ; WHV_CREATE_VPCI_DEVICE_FLAGS
  (notification-event-handle :pointer))   ; HANDLE optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WHvCreateVpciDevice = Win32::API::More->new('WinHvPlatform',
    'int WHvCreateVpciDevice(LPARAM Partition, UINT64 LogicalDeviceId, HANDLE VpciResource, int Flags, HANDLE NotificationEventHandle)');
# my $ret = $WHvCreateVpciDevice->Call($Partition, $LogicalDeviceId, $VpciResource, $Flags, $NotificationEventHandle);
# Partition : WHV_PARTITION_HANDLE -> LPARAM
# LogicalDeviceId : ULONGLONG -> UINT64
# VpciResource : HANDLE -> HANDLE
# Flags : WHV_CREATE_VPCI_DEVICE_FLAGS -> int
# NotificationEventHandle : HANDLE optional -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型