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

RmStartSession

関数
再起動マネージャーのセッションを開始する。
DLLrstrtmgr.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR RmStartSession(
    DWORD* pSessionHandle,
    DWORD dwSessionFlags,   // optional
    LPWSTR strSessionKey
);

パラメーター

名前方向説明
pSessionHandleDWORD*out開始された再起動マネージャーセッションのハンドルを受け取る変数へのポインター。
dwSessionFlagsDWORDoptional予約済み。0 を指定する。
strSessionKeyLPWSTRout生成されたセッションキーを受け取るバッファー。CCH_RM_SESSION_KEY+1 文字分が必要。

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR RmStartSession(
    DWORD* pSessionHandle,
    DWORD dwSessionFlags,   // optional
    LPWSTR strSessionKey
);
[DllImport("rstrtmgr.dll", ExactSpelling = true)]
static extern uint RmStartSession(
    out uint pSessionHandle,   // DWORD* out
    uint dwSessionFlags,   // DWORD optional
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder strSessionKey   // LPWSTR out
);
<DllImport("rstrtmgr.dll", ExactSpelling:=True)>
Public Shared Function RmStartSession(
    <Out> ByRef pSessionHandle As UInteger,   ' DWORD* out
    dwSessionFlags As UInteger,   ' DWORD optional
    <MarshalAs(UnmanagedType.LPWStr)> strSessionKey As System.Text.StringBuilder   ' LPWSTR out
) As UInteger
End Function
' pSessionHandle : DWORD* out
' dwSessionFlags : DWORD optional
' strSessionKey : LPWSTR out
Declare PtrSafe Function RmStartSession Lib "rstrtmgr" ( _
    ByRef pSessionHandle As Long, _
    ByVal dwSessionFlags As Long, _
    ByVal strSessionKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RmStartSession = ctypes.windll.rstrtmgr.RmStartSession
RmStartSession.restype = wintypes.DWORD
RmStartSession.argtypes = [
    ctypes.POINTER(wintypes.DWORD),  # pSessionHandle : DWORD* out
    wintypes.DWORD,  # dwSessionFlags : DWORD optional
    wintypes.LPWSTR,  # strSessionKey : LPWSTR out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('rstrtmgr.dll')
RmStartSession = Fiddle::Function.new(
  lib['RmStartSession'],
  [
    Fiddle::TYPE_VOIDP,  # pSessionHandle : DWORD* out
    -Fiddle::TYPE_INT,  # dwSessionFlags : DWORD optional
    Fiddle::TYPE_VOIDP,  # strSessionKey : LPWSTR out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "rstrtmgr")]
extern "system" {
    fn RmStartSession(
        pSessionHandle: *mut u32,  // DWORD* out
        dwSessionFlags: u32,  // DWORD optional
        strSessionKey: *mut u16  // LPWSTR out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("rstrtmgr.dll")]
public static extern uint RmStartSession(out uint pSessionHandle, uint dwSessionFlags, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder strSessionKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'rstrtmgr_RmStartSession' -Namespace Win32 -PassThru
# $api::RmStartSession(pSessionHandle, dwSessionFlags, strSessionKey)
#uselib "rstrtmgr.dll"
#func global RmStartSession "RmStartSession" sptr, sptr, sptr
; RmStartSession varptr(pSessionHandle), dwSessionFlags, varptr(strSessionKey)   ; 戻り値は stat
; pSessionHandle : DWORD* out -> "sptr"
; dwSessionFlags : DWORD optional -> "sptr"
; strSessionKey : LPWSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "rstrtmgr.dll"
#cfunc global RmStartSession "RmStartSession" var, int, var
; res = RmStartSession(pSessionHandle, dwSessionFlags, strSessionKey)
; pSessionHandle : DWORD* out -> "var"
; dwSessionFlags : DWORD optional -> "int"
; strSessionKey : LPWSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR RmStartSession(DWORD* pSessionHandle, DWORD dwSessionFlags, LPWSTR strSessionKey)
#uselib "rstrtmgr.dll"
#cfunc global RmStartSession "RmStartSession" var, int, var
; res = RmStartSession(pSessionHandle, dwSessionFlags, strSessionKey)
; pSessionHandle : DWORD* out -> "var"
; dwSessionFlags : DWORD optional -> "int"
; strSessionKey : LPWSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	rstrtmgr = windows.NewLazySystemDLL("rstrtmgr.dll")
	procRmStartSession = rstrtmgr.NewProc("RmStartSession")
)

// pSessionHandle (DWORD* out), dwSessionFlags (DWORD optional), strSessionKey (LPWSTR out)
r1, _, err := procRmStartSession.Call(
	uintptr(pSessionHandle),
	uintptr(dwSessionFlags),
	uintptr(strSessionKey),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function RmStartSession(
  pSessionHandle: Pointer;   // DWORD* out
  dwSessionFlags: DWORD;   // DWORD optional
  strSessionKey: PWideChar   // LPWSTR out
): DWORD; stdcall;
  external 'rstrtmgr.dll' name 'RmStartSession';
result := DllCall("rstrtmgr\RmStartSession"
    , "Ptr", pSessionHandle   ; DWORD* out
    , "UInt", dwSessionFlags   ; DWORD optional
    , "Ptr", strSessionKey   ; LPWSTR out
    , "UInt")   ; return: WIN32_ERROR
●RmStartSession(pSessionHandle, dwSessionFlags, strSessionKey) = DLL("rstrtmgr.dll", "dword RmStartSession(void*, dword, char*)")
# 呼び出し: RmStartSession(pSessionHandle, dwSessionFlags, strSessionKey)
# pSessionHandle : DWORD* out -> "void*"
# dwSessionFlags : DWORD optional -> "dword"
# strSessionKey : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef RmStartSessionNative = Uint32 Function(Pointer<Uint32>, Uint32, Pointer<Utf16>);
typedef RmStartSessionDart = int Function(Pointer<Uint32>, int, Pointer<Utf16>);
final RmStartSession = DynamicLibrary.open('rstrtmgr.dll')
    .lookupFunction<RmStartSessionNative, RmStartSessionDart>('RmStartSession');
// pSessionHandle : DWORD* out -> Pointer<Uint32>
// dwSessionFlags : DWORD optional -> Uint32
// strSessionKey : LPWSTR out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RmStartSession(
  pSessionHandle: Pointer;   // DWORD* out
  dwSessionFlags: DWORD;   // DWORD optional
  strSessionKey: PWideChar   // LPWSTR out
): DWORD; stdcall;
  external 'rstrtmgr.dll' name 'RmStartSession';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RmStartSession"
  c_RmStartSession :: Ptr Word32 -> Word32 -> CWString -> IO Word32
-- pSessionHandle : DWORD* out -> Ptr Word32
-- dwSessionFlags : DWORD optional -> Word32
-- strSessionKey : LPWSTR out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rmstartsession =
  foreign "RmStartSession"
    ((ptr uint32_t) @-> uint32_t @-> (ptr uint16_t) @-> returning uint32_t)
(* pSessionHandle : DWORD* out -> (ptr uint32_t) *)
(* dwSessionFlags : DWORD optional -> uint32_t *)
(* strSessionKey : LPWSTR out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library rstrtmgr (t "rstrtmgr.dll"))
(cffi:use-foreign-library rstrtmgr)

(cffi:defcfun ("RmStartSession" rm-start-session :convention :stdcall) :uint32
  (p-session-handle :pointer)   ; DWORD* out
  (dw-session-flags :uint32)   ; DWORD optional
  (str-session-key :pointer))   ; LPWSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RmStartSession = Win32::API::More->new('rstrtmgr',
    'DWORD RmStartSession(LPVOID pSessionHandle, DWORD dwSessionFlags, LPWSTR strSessionKey)');
# my $ret = $RmStartSession->Call($pSessionHandle, $dwSessionFlags, $strSessionKey);
# pSessionHandle : DWORD* out -> LPVOID
# dwSessionFlags : DWORD optional -> DWORD
# strSessionKey : LPWSTR out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型