ホーム › System.StationsAndDesktops › OpenWindowStationW
OpenWindowStationW
関数既存のウィンドウステーションを開いてハンドルを取得する。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
HWINSTA OpenWindowStationW(
LPCWSTR lpszWinSta,
BOOL fInherit,
DWORD dwDesiredAccess
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpszWinSta | LPCWSTR | in |
| fInherit | BOOL | in |
| dwDesiredAccess | DWORD | in |
戻り値の型: HWINSTA
各言語での呼び出し定義
// USER32.dll (Unicode / -W)
#include <windows.h>
HWINSTA OpenWindowStationW(
LPCWSTR lpszWinSta,
BOOL fInherit,
DWORD dwDesiredAccess
);[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr OpenWindowStationW(
[MarshalAs(UnmanagedType.LPWStr)] string lpszWinSta, // LPCWSTR
bool fInherit, // BOOL
uint dwDesiredAccess // DWORD
);<DllImport("USER32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function OpenWindowStationW(
<MarshalAs(UnmanagedType.LPWStr)> lpszWinSta As String, ' LPCWSTR
fInherit As Boolean, ' BOOL
dwDesiredAccess As UInteger ' DWORD
) As IntPtr
End Function' lpszWinSta : LPCWSTR
' fInherit : BOOL
' dwDesiredAccess : DWORD
Declare PtrSafe Function OpenWindowStationW Lib "user32" ( _
ByVal lpszWinSta As LongPtr, _
ByVal fInherit As Long, _
ByVal dwDesiredAccess As Long) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
OpenWindowStationW = ctypes.windll.user32.OpenWindowStationW
OpenWindowStationW.restype = ctypes.c_void_p
OpenWindowStationW.argtypes = [
wintypes.LPCWSTR, # lpszWinSta : LPCWSTR
wintypes.BOOL, # fInherit : BOOL
wintypes.DWORD, # dwDesiredAccess : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
OpenWindowStationW = Fiddle::Function.new(
lib['OpenWindowStationW'],
[
Fiddle::TYPE_VOIDP, # lpszWinSta : LPCWSTR
Fiddle::TYPE_INT, # fInherit : BOOL
-Fiddle::TYPE_INT, # dwDesiredAccess : DWORD
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "user32")]
extern "system" {
fn OpenWindowStationW(
lpszWinSta: *const u16, // LPCWSTR
fInherit: i32, // BOOL
dwDesiredAccess: u32 // DWORD
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr OpenWindowStationW([MarshalAs(UnmanagedType.LPWStr)] string lpszWinSta, bool fInherit, uint dwDesiredAccess);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_OpenWindowStationW' -Namespace Win32 -PassThru
# $api::OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess)#uselib "USER32.dll"
#func global OpenWindowStationW "OpenWindowStationW" wptr, wptr, wptr
; OpenWindowStationW lpszWinSta, fInherit, dwDesiredAccess ; 戻り値は stat
; lpszWinSta : LPCWSTR -> "wptr"
; fInherit : BOOL -> "wptr"
; dwDesiredAccess : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global OpenWindowStationW "OpenWindowStationW" wstr, int, int
; res = OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess)
; lpszWinSta : LPCWSTR -> "wstr"
; fInherit : BOOL -> "int"
; dwDesiredAccess : DWORD -> "int"; HWINSTA OpenWindowStationW(LPCWSTR lpszWinSta, BOOL fInherit, DWORD dwDesiredAccess)
#uselib "USER32.dll"
#cfunc global OpenWindowStationW "OpenWindowStationW" wstr, int, int
; res = OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess)
; lpszWinSta : LPCWSTR -> "wstr"
; fInherit : BOOL -> "int"
; dwDesiredAccess : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procOpenWindowStationW = user32.NewProc("OpenWindowStationW")
)
// lpszWinSta (LPCWSTR), fInherit (BOOL), dwDesiredAccess (DWORD)
r1, _, err := procOpenWindowStationW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszWinSta))),
uintptr(fInherit),
uintptr(dwDesiredAccess),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HWINSTAfunction OpenWindowStationW(
lpszWinSta: PWideChar; // LPCWSTR
fInherit: BOOL; // BOOL
dwDesiredAccess: DWORD // DWORD
): THandle; stdcall;
external 'USER32.dll' name 'OpenWindowStationW';result := DllCall("USER32\OpenWindowStationW"
, "WStr", lpszWinSta ; LPCWSTR
, "Int", fInherit ; BOOL
, "UInt", dwDesiredAccess ; DWORD
, "Ptr") ; return: HWINSTA●OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess) = DLL("USER32.dll", "void* OpenWindowStationW(char*, bool, dword)")
# 呼び出し: OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess)
# lpszWinSta : LPCWSTR -> "char*"
# fInherit : BOOL -> "bool"
# dwDesiredAccess : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。