ホーム › System.StationsAndDesktops › OpenWindowStationW
OpenWindowStationW
関数既存のウィンドウステーションを開いてハンドルを取得する。
シグネチャ
// USER32.dll (Unicode / -W)
#include <windows.h>
HWINSTA OpenWindowStationW(
LPCWSTR lpszWinSta,
BOOL fInherit,
DWORD dwDesiredAccess
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpszWinSta | LPCWSTR | in | 開く既存ウィンドウステーションの名前(Unicode)。 |
| fInherit | BOOL | in | 子プロセスがこのハンドルを継承するかを示す。TRUE で継承可。 |
| dwDesiredAccess | DWORD | in | 要求するアクセス権。WINSTA_ENUMERATE 等のアクセスマスク。 |
戻り値の型: 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 版の利用を推奨。const std = @import("std");
extern "user32" fn OpenWindowStationW(
lpszWinSta: [*c]const u16, // LPCWSTR
fInherit: i32, // BOOL
dwDesiredAccess: u32 // DWORD
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc OpenWindowStationW(
lpszWinSta: WideCString, # LPCWSTR
fInherit: int32, # BOOL
dwDesiredAccess: uint32 # DWORD
): pointer {.importc: "OpenWindowStationW", stdcall, dynlib: "USER32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "user32");
extern(Windows)
void* OpenWindowStationW(
const(wchar)* lpszWinSta, // LPCWSTR
int fInherit, // BOOL
uint dwDesiredAccess // DWORD
);ccall((:OpenWindowStationW, "USER32.dll"), stdcall, Ptr{Cvoid},
(Cwstring, Int32, UInt32),
lpszWinSta, fInherit, dwDesiredAccess)
# lpszWinSta : LPCWSTR -> Cwstring
# fInherit : BOOL -> Int32
# dwDesiredAccess : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
void* OpenWindowStationW(
const uint16_t* lpszWinSta,
int32_t fInherit,
uint32_t dwDesiredAccess);
]]
local user32 = ffi.load("user32")
-- user32.OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess)
-- lpszWinSta : LPCWSTR
-- fInherit : BOOL
-- dwDesiredAccess : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('USER32.dll');
const OpenWindowStationW = lib.func('__stdcall', 'OpenWindowStationW', 'void *', ['str16', 'int32_t', 'uint32_t']);
// OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess)
// lpszWinSta : LPCWSTR -> 'str16'
// fInherit : BOOL -> 'int32_t'
// dwDesiredAccess : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USER32.dll", {
OpenWindowStationW: { parameters: ["buffer", "i32", "u32"], result: "pointer" },
});
// lib.symbols.OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess)
// lpszWinSta : LPCWSTR -> "buffer"
// fInherit : BOOL -> "i32"
// dwDesiredAccess : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* OpenWindowStationW(
const uint16_t* lpszWinSta,
int32_t fInherit,
uint32_t dwDesiredAccess);
C, "USER32.dll");
// $ffi->OpenWindowStationW(lpszWinSta, fInherit, dwDesiredAccess);
// lpszWinSta : LPCWSTR
// fInherit : BOOL
// dwDesiredAccess : DWORD
// 構造体/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 User32 extends StdCallLibrary {
User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.UNICODE_OPTIONS);
Pointer OpenWindowStationW(
WString lpszWinSta, // LPCWSTR
boolean fInherit, // BOOL
int dwDesiredAccess // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("user32")]
lib LibUSER32
fun OpenWindowStationW = OpenWindowStationW(
lpszWinSta : UInt16*, # LPCWSTR
fInherit : Int32, # BOOL
dwDesiredAccess : UInt32 # DWORD
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef OpenWindowStationWNative = Pointer<Void> Function(Pointer<Utf16>, Int32, Uint32);
typedef OpenWindowStationWDart = Pointer<Void> Function(Pointer<Utf16>, int, int);
final OpenWindowStationW = DynamicLibrary.open('USER32.dll')
.lookupFunction<OpenWindowStationWNative, OpenWindowStationWDart>('OpenWindowStationW');
// lpszWinSta : LPCWSTR -> Pointer<Utf16>
// fInherit : BOOL -> Int32
// dwDesiredAccess : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function OpenWindowStationW(
lpszWinSta: PWideChar; // LPCWSTR
fInherit: BOOL; // BOOL
dwDesiredAccess: DWORD // DWORD
): THandle; stdcall;
external 'USER32.dll' name 'OpenWindowStationW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "OpenWindowStationW"
c_OpenWindowStationW :: CWString -> CInt -> Word32 -> IO (Ptr ())
-- lpszWinSta : LPCWSTR -> CWString
-- fInherit : BOOL -> CInt
-- dwDesiredAccess : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let openwindowstationw =
foreign "OpenWindowStationW"
((ptr uint16_t) @-> int32_t @-> uint32_t @-> returning (ptr void))
(* lpszWinSta : LPCWSTR -> (ptr uint16_t) *)
(* fInherit : BOOL -> int32_t *)
(* dwDesiredAccess : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library user32 (t "USER32.dll"))
(cffi:use-foreign-library user32)
(cffi:defcfun ("OpenWindowStationW" open-window-station-w :convention :stdcall) :pointer
(lpsz-win-sta (:string :encoding :utf-16le)) ; LPCWSTR
(f-inherit :int32) ; BOOL
(dw-desired-access :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $OpenWindowStationW = Win32::API::More->new('USER32',
'HANDLE OpenWindowStationW(LPCWSTR lpszWinSta, BOOL fInherit, DWORD dwDesiredAccess)');
# my $ret = $OpenWindowStationW->Call($lpszWinSta, $fInherit, $dwDesiredAccess);
# lpszWinSta : LPCWSTR -> LPCWSTR
# fInherit : BOOL -> BOOL
# dwDesiredAccess : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f OpenWindowStationA (ANSI版) — 既存のウィンドウステーションを開いてハンドルを取得する。