DoEnvironmentSubstW
関数文字列内の環境変数参照を実際の値に置換する。
シグネチャ
// SHELL32.dll (Unicode / -W)
#include <windows.h>
DWORD DoEnvironmentSubstW(
LPWSTR pszSrc,
DWORD cchSrc
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszSrc | LPWSTR | inout |
| cchSrc | DWORD | in |
戻り値の型: DWORD
各言語での呼び出し定義
// SHELL32.dll (Unicode / -W)
#include <windows.h>
DWORD DoEnvironmentSubstW(
LPWSTR pszSrc,
DWORD cchSrc
);[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DoEnvironmentSubstW(
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszSrc, // LPWSTR in/out
uint cchSrc // DWORD
);<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DoEnvironmentSubstW(
<MarshalAs(UnmanagedType.LPWStr)> pszSrc As System.Text.StringBuilder, ' LPWSTR in/out
cchSrc As UInteger ' DWORD
) As UInteger
End Function' pszSrc : LPWSTR in/out
' cchSrc : DWORD
Declare PtrSafe Function DoEnvironmentSubstW Lib "shell32" ( _
ByVal pszSrc As LongPtr, _
ByVal cchSrc As Long) As Long
' 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
DoEnvironmentSubstW = ctypes.windll.shell32.DoEnvironmentSubstW
DoEnvironmentSubstW.restype = wintypes.DWORD
DoEnvironmentSubstW.argtypes = [
wintypes.LPWSTR, # pszSrc : LPWSTR in/out
wintypes.DWORD, # cchSrc : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
DoEnvironmentSubstW = Fiddle::Function.new(
lib['DoEnvironmentSubstW'],
[
Fiddle::TYPE_VOIDP, # pszSrc : LPWSTR in/out
-Fiddle::TYPE_INT, # cchSrc : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "shell32")]
extern "system" {
fn DoEnvironmentSubstW(
pszSrc: *mut u16, // LPWSTR in/out
cchSrc: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern uint DoEnvironmentSubstW([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszSrc, uint cchSrc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_DoEnvironmentSubstW' -Namespace Win32 -PassThru
# $api::DoEnvironmentSubstW(pszSrc, cchSrc)#uselib "SHELL32.dll"
#func global DoEnvironmentSubstW "DoEnvironmentSubstW" wptr, wptr
; DoEnvironmentSubstW varptr(pszSrc), cchSrc ; 戻り値は stat
; pszSrc : LPWSTR in/out -> "wptr"
; cchSrc : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SHELL32.dll" #cfunc global DoEnvironmentSubstW "DoEnvironmentSubstW" var, int ; res = DoEnvironmentSubstW(pszSrc, cchSrc) ; pszSrc : LPWSTR in/out -> "var" ; cchSrc : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global DoEnvironmentSubstW "DoEnvironmentSubstW" sptr, int ; res = DoEnvironmentSubstW(varptr(pszSrc), cchSrc) ; pszSrc : LPWSTR in/out -> "sptr" ; cchSrc : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DoEnvironmentSubstW(LPWSTR pszSrc, DWORD cchSrc) #uselib "SHELL32.dll" #cfunc global DoEnvironmentSubstW "DoEnvironmentSubstW" var, int ; res = DoEnvironmentSubstW(pszSrc, cchSrc) ; pszSrc : LPWSTR in/out -> "var" ; cchSrc : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DoEnvironmentSubstW(LPWSTR pszSrc, DWORD cchSrc) #uselib "SHELL32.dll" #cfunc global DoEnvironmentSubstW "DoEnvironmentSubstW" intptr, int ; res = DoEnvironmentSubstW(varptr(pszSrc), cchSrc) ; pszSrc : LPWSTR in/out -> "intptr" ; cchSrc : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procDoEnvironmentSubstW = shell32.NewProc("DoEnvironmentSubstW")
)
// pszSrc (LPWSTR in/out), cchSrc (DWORD)
r1, _, err := procDoEnvironmentSubstW.Call(
uintptr(pszSrc),
uintptr(cchSrc),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DoEnvironmentSubstW(
pszSrc: PWideChar; // LPWSTR in/out
cchSrc: DWORD // DWORD
): DWORD; stdcall;
external 'SHELL32.dll' name 'DoEnvironmentSubstW';result := DllCall("SHELL32\DoEnvironmentSubstW"
, "Ptr", pszSrc ; LPWSTR in/out
, "UInt", cchSrc ; DWORD
, "UInt") ; return: DWORD●DoEnvironmentSubstW(pszSrc, cchSrc) = DLL("SHELL32.dll", "dword DoEnvironmentSubstW(char*, dword)")
# 呼び出し: DoEnvironmentSubstW(pszSrc, cchSrc)
# pszSrc : LPWSTR in/out -> "char*"
# cchSrc : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。