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

GetEnvironmentStringsW

関数
現在のプロセスの環境ブロックを取得する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

LPWSTR GetEnvironmentStringsW(void);

パラメーターなし。戻り値: LPWSTR

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

LPWSTR GetEnvironmentStringsW(void);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr GetEnvironmentStringsW();
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetEnvironmentStringsW() As IntPtr
End Function
Declare PtrSafe Function GetEnvironmentStringsW Lib "kernel32" () 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

GetEnvironmentStringsW = ctypes.windll.kernel32.GetEnvironmentStringsW
GetEnvironmentStringsW.restype = wintypes.LPWSTR
GetEnvironmentStringsW.argtypes = []
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetEnvironmentStringsW = Fiddle::Function.new(
  lib['GetEnvironmentStringsW'],
  [],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn GetEnvironmentStringsW() -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr GetEnvironmentStringsW();
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetEnvironmentStringsW' -Namespace Win32 -PassThru
# $api::GetEnvironmentStringsW()
#uselib "KERNEL32.dll"
#func global GetEnvironmentStringsW "GetEnvironmentStringsW"
; GetEnvironmentStringsW   ; 戻り値は stat
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global GetEnvironmentStringsW "GetEnvironmentStringsW"
; res = GetEnvironmentStringsW()
; LPWSTR GetEnvironmentStringsW()
#uselib "KERNEL32.dll"
#cfunc global GetEnvironmentStringsW "GetEnvironmentStringsW"
; res = GetEnvironmentStringsW()
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetEnvironmentStringsW = kernel32.NewProc("GetEnvironmentStringsW")
)

r1, _, err := procGetEnvironmentStringsW.Call()
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // LPWSTR
function GetEnvironmentStringsW: PWideChar; stdcall;
  external 'KERNEL32.dll' name 'GetEnvironmentStringsW';
result := DllCall("KERNEL32\GetEnvironmentStringsW", "Ptr")
●GetEnvironmentStringsW() = DLL("KERNEL32.dll", "char* GetEnvironmentStringsW()")
# 呼び出し: GetEnvironmentStringsW()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。