ホーム › System.HostComputeSystem › HcsAddResourceToOperation
HcsAddResourceToOperation
関数HCS操作にハンドル等のリソースを追加する。
シグネチャ
// computecore.dll
#include <windows.h>
HRESULT HcsAddResourceToOperation(
HCS_OPERATION operation,
HCS_RESOURCE_TYPE type,
LPCWSTR uri,
HANDLE handle
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| operation | HCS_OPERATION | in | リソースを関連付ける対象のHCS操作ハンドル。 |
| type | HCS_RESOURCE_TYPE | in | 追加するリソースの種別を示す列挙値。ファイルやVHD等を指定する。 |
| uri | LPCWSTR | in | リソースを識別するURI文字列。 |
| handle | HANDLE | in | リソースに対応するOSハンドル。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// computecore.dll
#include <windows.h>
HRESULT HcsAddResourceToOperation(
HCS_OPERATION operation,
HCS_RESOURCE_TYPE type,
LPCWSTR uri,
HANDLE handle
);[DllImport("computecore.dll", ExactSpelling = true)]
static extern int HcsAddResourceToOperation(
IntPtr operation, // HCS_OPERATION
int type, // HCS_RESOURCE_TYPE
[MarshalAs(UnmanagedType.LPWStr)] string uri, // LPCWSTR
IntPtr handle // HANDLE
);<DllImport("computecore.dll", ExactSpelling:=True)>
Public Shared Function HcsAddResourceToOperation(
operation As IntPtr, ' HCS_OPERATION
type As Integer, ' HCS_RESOURCE_TYPE
<MarshalAs(UnmanagedType.LPWStr)> uri As String, ' LPCWSTR
handle As IntPtr ' HANDLE
) As Integer
End Function' operation : HCS_OPERATION
' type : HCS_RESOURCE_TYPE
' uri : LPCWSTR
' handle : HANDLE
Declare PtrSafe Function HcsAddResourceToOperation Lib "computecore" ( _
ByVal operation As LongPtr, _
ByVal type As Long, _
ByVal uri As LongPtr, _
ByVal handle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
HcsAddResourceToOperation = ctypes.windll.computecore.HcsAddResourceToOperation
HcsAddResourceToOperation.restype = ctypes.c_int
HcsAddResourceToOperation.argtypes = [
wintypes.HANDLE, # operation : HCS_OPERATION
ctypes.c_int, # type : HCS_RESOURCE_TYPE
wintypes.LPCWSTR, # uri : LPCWSTR
wintypes.HANDLE, # handle : HANDLE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('computecore.dll')
HcsAddResourceToOperation = Fiddle::Function.new(
lib['HcsAddResourceToOperation'],
[
Fiddle::TYPE_VOIDP, # operation : HCS_OPERATION
Fiddle::TYPE_INT, # type : HCS_RESOURCE_TYPE
Fiddle::TYPE_VOIDP, # uri : LPCWSTR
Fiddle::TYPE_VOIDP, # handle : HANDLE
],
Fiddle::TYPE_INT)#[link(name = "computecore")]
extern "system" {
fn HcsAddResourceToOperation(
operation: *mut core::ffi::c_void, // HCS_OPERATION
type: i32, // HCS_RESOURCE_TYPE
uri: *const u16, // LPCWSTR
handle: *mut core::ffi::c_void // HANDLE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("computecore.dll")]
public static extern int HcsAddResourceToOperation(IntPtr operation, int type, [MarshalAs(UnmanagedType.LPWStr)] string uri, IntPtr handle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'computecore_HcsAddResourceToOperation' -Namespace Win32 -PassThru
# $api::HcsAddResourceToOperation(operation, type, uri, handle)#uselib "computecore.dll"
#func global HcsAddResourceToOperation "HcsAddResourceToOperation" sptr, sptr, sptr, sptr
; HcsAddResourceToOperation operation, type, uri, handle ; 戻り値は stat
; operation : HCS_OPERATION -> "sptr"
; type : HCS_RESOURCE_TYPE -> "sptr"
; uri : LPCWSTR -> "sptr"
; handle : HANDLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "computecore.dll"
#cfunc global HcsAddResourceToOperation "HcsAddResourceToOperation" sptr, int, wstr, sptr
; res = HcsAddResourceToOperation(operation, type, uri, handle)
; operation : HCS_OPERATION -> "sptr"
; type : HCS_RESOURCE_TYPE -> "int"
; uri : LPCWSTR -> "wstr"
; handle : HANDLE -> "sptr"; HRESULT HcsAddResourceToOperation(HCS_OPERATION operation, HCS_RESOURCE_TYPE type, LPCWSTR uri, HANDLE handle)
#uselib "computecore.dll"
#cfunc global HcsAddResourceToOperation "HcsAddResourceToOperation" intptr, int, wstr, intptr
; res = HcsAddResourceToOperation(operation, type, uri, handle)
; operation : HCS_OPERATION -> "intptr"
; type : HCS_RESOURCE_TYPE -> "int"
; uri : LPCWSTR -> "wstr"
; handle : HANDLE -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
computecore = windows.NewLazySystemDLL("computecore.dll")
procHcsAddResourceToOperation = computecore.NewProc("HcsAddResourceToOperation")
)
// operation (HCS_OPERATION), type (HCS_RESOURCE_TYPE), uri (LPCWSTR), handle (HANDLE)
r1, _, err := procHcsAddResourceToOperation.Call(
uintptr(operation),
uintptr(type),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(uri))),
uintptr(handle),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction HcsAddResourceToOperation(
operation: THandle; // HCS_OPERATION
type: Integer; // HCS_RESOURCE_TYPE
uri: PWideChar; // LPCWSTR
handle: THandle // HANDLE
): Integer; stdcall;
external 'computecore.dll' name 'HcsAddResourceToOperation';result := DllCall("computecore\HcsAddResourceToOperation"
, "Ptr", operation ; HCS_OPERATION
, "Int", type ; HCS_RESOURCE_TYPE
, "WStr", uri ; LPCWSTR
, "Ptr", handle ; HANDLE
, "Int") ; return: HRESULT●HcsAddResourceToOperation(operation, type, uri, handle) = DLL("computecore.dll", "int HcsAddResourceToOperation(void*, int, char*, void*)")
# 呼び出し: HcsAddResourceToOperation(operation, type, uri, handle)
# operation : HCS_OPERATION -> "void*"
# type : HCS_RESOURCE_TYPE -> "int"
# uri : LPCWSTR -> "char*"
# handle : HANDLE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "computecore" fn HcsAddResourceToOperation(
operation: ?*anyopaque, // HCS_OPERATION
type: i32, // HCS_RESOURCE_TYPE
uri: [*c]const u16, // LPCWSTR
handle: ?*anyopaque // HANDLE
) callconv(std.os.windows.WINAPI) i32;proc HcsAddResourceToOperation(
operation: pointer, # HCS_OPERATION
`type`: int32, # HCS_RESOURCE_TYPE
uri: WideCString, # LPCWSTR
handle: pointer # HANDLE
): int32 {.importc: "HcsAddResourceToOperation", stdcall, dynlib: "computecore.dll".}pragma(lib, "computecore");
extern(Windows)
int HcsAddResourceToOperation(
void* operation, // HCS_OPERATION
int type, // HCS_RESOURCE_TYPE
const(wchar)* uri, // LPCWSTR
void* handle // HANDLE
);ccall((:HcsAddResourceToOperation, "computecore.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Cwstring, Ptr{Cvoid}),
operation, type, uri, handle)
# operation : HCS_OPERATION -> Ptr{Cvoid}
# type : HCS_RESOURCE_TYPE -> Int32
# uri : LPCWSTR -> Cwstring
# handle : HANDLE -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t HcsAddResourceToOperation(
void* operation,
int32_t type,
const uint16_t* uri,
void* handle);
]]
local computecore = ffi.load("computecore")
-- computecore.HcsAddResourceToOperation(operation, type, uri, handle)
-- operation : HCS_OPERATION
-- type : HCS_RESOURCE_TYPE
-- uri : LPCWSTR
-- handle : HANDLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('computecore.dll');
const HcsAddResourceToOperation = lib.func('__stdcall', 'HcsAddResourceToOperation', 'int32_t', ['void *', 'int32_t', 'str16', 'void *']);
// HcsAddResourceToOperation(operation, type, uri, handle)
// operation : HCS_OPERATION -> 'void *'
// type : HCS_RESOURCE_TYPE -> 'int32_t'
// uri : LPCWSTR -> 'str16'
// handle : HANDLE -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("computecore.dll", {
HcsAddResourceToOperation: { parameters: ["pointer", "i32", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.HcsAddResourceToOperation(operation, type, uri, handle)
// operation : HCS_OPERATION -> "pointer"
// type : HCS_RESOURCE_TYPE -> "i32"
// uri : LPCWSTR -> "buffer"
// handle : HANDLE -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t HcsAddResourceToOperation(
void* operation,
int32_t type,
const uint16_t* uri,
void* handle);
C, "computecore.dll");
// $ffi->HcsAddResourceToOperation(operation, type, uri, handle);
// operation : HCS_OPERATION
// type : HCS_RESOURCE_TYPE
// uri : LPCWSTR
// handle : HANDLE
// 構造体/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 Computecore extends StdCallLibrary {
Computecore INSTANCE = Native.load("computecore", Computecore.class);
int HcsAddResourceToOperation(
Pointer operation, // HCS_OPERATION
int type, // HCS_RESOURCE_TYPE
WString uri, // LPCWSTR
Pointer handle // HANDLE
);
}@[Link("computecore")]
lib Libcomputecore
fun HcsAddResourceToOperation = HcsAddResourceToOperation(
operation : Void*, # HCS_OPERATION
type_ : Int32, # HCS_RESOURCE_TYPE
uri : UInt16*, # LPCWSTR
handle : Void* # HANDLE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef HcsAddResourceToOperationNative = Int32 Function(Pointer<Void>, Int32, Pointer<Utf16>, Pointer<Void>);
typedef HcsAddResourceToOperationDart = int Function(Pointer<Void>, int, Pointer<Utf16>, Pointer<Void>);
final HcsAddResourceToOperation = DynamicLibrary.open('computecore.dll')
.lookupFunction<HcsAddResourceToOperationNative, HcsAddResourceToOperationDart>('HcsAddResourceToOperation');
// operation : HCS_OPERATION -> Pointer<Void>
// type : HCS_RESOURCE_TYPE -> Int32
// uri : LPCWSTR -> Pointer<Utf16>
// handle : HANDLE -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function HcsAddResourceToOperation(
operation: THandle; // HCS_OPERATION
type: Integer; // HCS_RESOURCE_TYPE
uri: PWideChar; // LPCWSTR
handle: THandle // HANDLE
): Integer; stdcall;
external 'computecore.dll' name 'HcsAddResourceToOperation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "HcsAddResourceToOperation"
c_HcsAddResourceToOperation :: Ptr () -> Int32 -> CWString -> Ptr () -> IO Int32
-- operation : HCS_OPERATION -> Ptr ()
-- type : HCS_RESOURCE_TYPE -> Int32
-- uri : LPCWSTR -> CWString
-- handle : HANDLE -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let hcsaddresourcetooperation =
foreign "HcsAddResourceToOperation"
((ptr void) @-> int32_t @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* operation : HCS_OPERATION -> (ptr void) *)
(* type : HCS_RESOURCE_TYPE -> int32_t *)
(* uri : LPCWSTR -> (ptr uint16_t) *)
(* handle : HANDLE -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library computecore (t "computecore.dll"))
(cffi:use-foreign-library computecore)
(cffi:defcfun ("HcsAddResourceToOperation" hcs-add-resource-to-operation :convention :stdcall) :int32
(operation :pointer) ; HCS_OPERATION
(type :int32) ; HCS_RESOURCE_TYPE
(uri (:string :encoding :utf-16le)) ; LPCWSTR
(handle :pointer)) ; HANDLE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $HcsAddResourceToOperation = Win32::API::More->new('computecore',
'int HcsAddResourceToOperation(HANDLE operation, int type, LPCWSTR uri, HANDLE handle)');
# my $ret = $HcsAddResourceToOperation->Call($operation, $type, $uri, $handle);
# operation : HCS_OPERATION -> HANDLE
# type : HCS_RESOURCE_TYPE -> int
# uri : LPCWSTR -> LPCWSTR
# handle : HANDLE -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型