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
strSessionKeyLPWSTRout

戻り値の型: 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)。