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
operationHCS_OPERATIONin
securityDescriptorSECURITY_DESCRIPTOR*inoptional
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)。