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

HcsModifyProcess

関数
コンピュートシステム内プロセスの設定を変更する。
DLLcomputecore.dll呼出規約winapi

シグネチャ

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

HRESULT HcsModifyProcess(
    HCS_PROCESS process,
    HCS_OPERATION operation,
    LPCWSTR settings
);

パラメーター

名前方向説明
processHCS_PROCESSin設定を変更する対象のプロセスハンドル。
operationHCS_OPERATIONin処理結果を受け取る非同期HCS操作のハンドル。
settingsLPCWSTRin変更内容を記述したJSON形式の設定文字列。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT HcsModifyProcess(
    HCS_PROCESS process,
    HCS_OPERATION operation,
    LPCWSTR settings
);
[DllImport("computecore.dll", ExactSpelling = true)]
static extern int HcsModifyProcess(
    IntPtr process,   // HCS_PROCESS
    IntPtr operation,   // HCS_OPERATION
    [MarshalAs(UnmanagedType.LPWStr)] string settings   // LPCWSTR
);
<DllImport("computecore.dll", ExactSpelling:=True)>
Public Shared Function HcsModifyProcess(
    process As IntPtr,   ' HCS_PROCESS
    operation As IntPtr,   ' HCS_OPERATION
    <MarshalAs(UnmanagedType.LPWStr)> settings As String   ' LPCWSTR
) As Integer
End Function
' process : HCS_PROCESS
' operation : HCS_OPERATION
' settings : LPCWSTR
Declare PtrSafe Function HcsModifyProcess Lib "computecore" ( _
    ByVal process As LongPtr, _
    ByVal operation As LongPtr, _
    ByVal settings As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HcsModifyProcess = ctypes.windll.computecore.HcsModifyProcess
HcsModifyProcess.restype = ctypes.c_int
HcsModifyProcess.argtypes = [
    wintypes.HANDLE,  # process : HCS_PROCESS
    wintypes.HANDLE,  # operation : HCS_OPERATION
    wintypes.LPCWSTR,  # settings : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	computecore = windows.NewLazySystemDLL("computecore.dll")
	procHcsModifyProcess = computecore.NewProc("HcsModifyProcess")
)

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

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

typedef HcsModifyProcessNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>);
typedef HcsModifyProcessDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>);
final HcsModifyProcess = DynamicLibrary.open('computecore.dll')
    .lookupFunction<HcsModifyProcessNative, HcsModifyProcessDart>('HcsModifyProcess');
// process : HCS_PROCESS -> Pointer<Void>
// operation : HCS_OPERATION -> Pointer<Void>
// settings : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function HcsModifyProcess(
  process: THandle;   // HCS_PROCESS
  operation: THandle;   // HCS_OPERATION
  settings: PWideChar   // LPCWSTR
): Integer; stdcall;
  external 'computecore.dll' name 'HcsModifyProcess';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "HcsModifyProcess"
  c_HcsModifyProcess :: Ptr () -> Ptr () -> CWString -> IO Int32
-- process : HCS_PROCESS -> Ptr ()
-- operation : HCS_OPERATION -> Ptr ()
-- settings : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let hcsmodifyprocess =
  foreign "HcsModifyProcess"
    ((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> returning int32_t)
(* process : HCS_PROCESS -> (ptr void) *)
(* operation : HCS_OPERATION -> (ptr void) *)
(* settings : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library computecore (t "computecore.dll"))
(cffi:use-foreign-library computecore)

(cffi:defcfun ("HcsModifyProcess" hcs-modify-process :convention :stdcall) :int32
  (process :pointer)   ; HCS_PROCESS
  (operation :pointer)   ; HCS_OPERATION
  (settings (:string :encoding :utf-16le)))   ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $HcsModifyProcess = Win32::API::More->new('computecore',
    'int HcsModifyProcess(HANDLE process, HANDLE operation, LPCWSTR settings)');
# my $ret = $HcsModifyProcess->Call($process, $operation, $settings);
# process : HCS_PROCESS -> HANDLE
# operation : HCS_OPERATION -> HANDLE
# settings : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。