Win32 API 日本語リファレンス
ホームUI.Shell › DoEnvironmentSubstA

DoEnvironmentSubstA

関数
文字列内の環境変数参照を実際の値に置換する。
DLLSHELL32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHELL32.dll  (ANSI / -A)
#include <windows.h>

DWORD DoEnvironmentSubstA(
    LPSTR pszSrc,
    DWORD cchSrc
);

パラメーター

名前方向
pszSrcLPSTRinout
cchSrcDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// SHELL32.dll  (ANSI / -A)
#include <windows.h>

DWORD DoEnvironmentSubstA(
    LPSTR pszSrc,
    DWORD cchSrc
);
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DoEnvironmentSubstA(
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszSrc,   // LPSTR in/out
    uint cchSrc   // DWORD
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DoEnvironmentSubstA(
    <MarshalAs(UnmanagedType.LPStr)> pszSrc As System.Text.StringBuilder,   ' LPSTR in/out
    cchSrc As UInteger   ' DWORD
) As UInteger
End Function
' pszSrc : LPSTR in/out
' cchSrc : DWORD
Declare PtrSafe Function DoEnvironmentSubstA Lib "shell32" ( _
    ByVal pszSrc As String, _
    ByVal cchSrc As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DoEnvironmentSubstA = ctypes.windll.shell32.DoEnvironmentSubstA
DoEnvironmentSubstA.restype = wintypes.DWORD
DoEnvironmentSubstA.argtypes = [
    wintypes.LPSTR,  # pszSrc : LPSTR in/out
    wintypes.DWORD,  # cchSrc : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
DoEnvironmentSubstA = Fiddle::Function.new(
  lib['DoEnvironmentSubstA'],
  [
    Fiddle::TYPE_VOIDP,  # pszSrc : LPSTR in/out
    -Fiddle::TYPE_INT,  # cchSrc : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn DoEnvironmentSubstA(
        pszSrc: *mut u8,  // LPSTR in/out
        cchSrc: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi)]
public static extern uint DoEnvironmentSubstA([MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszSrc, uint cchSrc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_DoEnvironmentSubstA' -Namespace Win32 -PassThru
# $api::DoEnvironmentSubstA(pszSrc, cchSrc)
#uselib "SHELL32.dll"
#func global DoEnvironmentSubstA "DoEnvironmentSubstA" sptr, sptr
; DoEnvironmentSubstA varptr(pszSrc), cchSrc   ; 戻り値は stat
; pszSrc : LPSTR in/out -> "sptr"
; cchSrc : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SHELL32.dll"
#cfunc global DoEnvironmentSubstA "DoEnvironmentSubstA" var, int
; res = DoEnvironmentSubstA(pszSrc, cchSrc)
; pszSrc : LPSTR in/out -> "var"
; cchSrc : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DoEnvironmentSubstA(LPSTR pszSrc, DWORD cchSrc)
#uselib "SHELL32.dll"
#cfunc global DoEnvironmentSubstA "DoEnvironmentSubstA" var, int
; res = DoEnvironmentSubstA(pszSrc, cchSrc)
; pszSrc : LPSTR in/out -> "var"
; cchSrc : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procDoEnvironmentSubstA = shell32.NewProc("DoEnvironmentSubstA")
)

// pszSrc (LPSTR in/out), cchSrc (DWORD)
r1, _, err := procDoEnvironmentSubstA.Call(
	uintptr(pszSrc),
	uintptr(cchSrc),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DoEnvironmentSubstA(
  pszSrc: PAnsiChar;   // LPSTR in/out
  cchSrc: DWORD   // DWORD
): DWORD; stdcall;
  external 'SHELL32.dll' name 'DoEnvironmentSubstA';
result := DllCall("SHELL32\DoEnvironmentSubstA"
    , "Ptr", pszSrc   ; LPSTR in/out
    , "UInt", cchSrc   ; DWORD
    , "UInt")   ; return: DWORD
●DoEnvironmentSubstA(pszSrc, cchSrc) = DLL("SHELL32.dll", "dword DoEnvironmentSubstA(char*, dword)")
# 呼び出し: DoEnvironmentSubstA(pszSrc, cchSrc)
# pszSrc : LPSTR in/out -> "char*"
# cchSrc : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。