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

HcsCreateProcess

関数
コンピュートシステム内で新しいプロセスを作成する。
DLLcomputecore.dll呼出規約winapi

シグネチャ

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

HRESULT HcsCreateProcess(
    HCS_SYSTEM computeSystem,
    LPCWSTR processParameters,
    HCS_OPERATION operation,
    const SECURITY_DESCRIPTOR* securityDescriptor,   // optional
    HCS_PROCESS* process
);

パラメーター

名前方向説明
computeSystemHCS_SYSTEMinプロセスを作成する対象の計算システムハンドル。
processParametersLPCWSTRin起動プロセスのコマンドや環境を記述したJSON文字列。
operationHCS_OPERATIONin作成結果を受け取る非同期HCS操作のハンドル。
securityDescriptorSECURITY_DESCRIPTOR*inoptionalプロセスに適用するセキュリティ記述子へのポインタ。NULL可。
processHCS_PROCESS*out生成されたプロセスのハンドルを受け取るポインタ。

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

HcsCreateProcess = ctypes.windll.computecore.HcsCreateProcess
HcsCreateProcess.restype = ctypes.c_int
HcsCreateProcess.argtypes = [
    wintypes.HANDLE,  # computeSystem : HCS_SYSTEM
    wintypes.LPCWSTR,  # processParameters : LPCWSTR
    wintypes.HANDLE,  # operation : HCS_OPERATION
    ctypes.c_void_p,  # securityDescriptor : SECURITY_DESCRIPTOR* optional
    ctypes.c_void_p,  # process : HCS_PROCESS* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	computecore = windows.NewLazySystemDLL("computecore.dll")
	procHcsCreateProcess = computecore.NewProc("HcsCreateProcess")
)

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

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

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

foreign import stdcall safe "HcsCreateProcess"
  c_HcsCreateProcess :: Ptr () -> CWString -> Ptr () -> Ptr () -> Ptr () -> IO Int32
-- computeSystem : HCS_SYSTEM -> Ptr ()
-- processParameters : LPCWSTR -> CWString
-- operation : HCS_OPERATION -> Ptr ()
-- securityDescriptor : SECURITY_DESCRIPTOR* optional -> Ptr ()
-- process : HCS_PROCESS* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

(cffi:defcfun ("HcsCreateProcess" hcs-create-process :convention :stdcall) :int32
  (compute-system :pointer)   ; HCS_SYSTEM
  (process-parameters (:string :encoding :utf-16le))   ; LPCWSTR
  (operation :pointer)   ; HCS_OPERATION
  (security-descriptor :pointer)   ; SECURITY_DESCRIPTOR* optional
  (process :pointer))   ; HCS_PROCESS* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $HcsCreateProcess = Win32::API::More->new('computecore',
    'int HcsCreateProcess(HANDLE computeSystem, LPCWSTR processParameters, HANDLE operation, LPVOID securityDescriptor, HANDLE process)');
# my $ret = $HcsCreateProcess->Call($computeSystem, $processParameters, $operation, $securityDescriptor, $process);
# computeSystem : HCS_SYSTEM -> HANDLE
# processParameters : LPCWSTR -> LPCWSTR
# operation : HCS_OPERATION -> HANDLE
# securityDescriptor : SECURITY_DESCRIPTOR* optional -> LPVOID
# process : HCS_PROCESS* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型