ホーム › Networking.Clustering › ResUtilExpandEnvironmentStrings
ResUtilExpandEnvironmentStrings
関数文字列内の環境変数を展開する。
シグネチャ
// RESUTILS.dll
#include <windows.h>
LPWSTR ResUtilExpandEnvironmentStrings(
LPCWSTR pszSrc
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszSrc | LPCWSTR | in | 環境変数参照(%VAR%形式)を含む入力文字列。展開結果が新規確保され返される。 |
戻り値の型: LPWSTR
各言語での呼び出し定義
// RESUTILS.dll
#include <windows.h>
LPWSTR ResUtilExpandEnvironmentStrings(
LPCWSTR pszSrc
);[DllImport("RESUTILS.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr ResUtilExpandEnvironmentStrings(
[MarshalAs(UnmanagedType.LPWStr)] string pszSrc // LPCWSTR
);<DllImport("RESUTILS.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ResUtilExpandEnvironmentStrings(
<MarshalAs(UnmanagedType.LPWStr)> pszSrc As String ' LPCWSTR
) As IntPtr
End Function' pszSrc : LPCWSTR
Declare PtrSafe Function ResUtilExpandEnvironmentStrings Lib "resutils" ( _
ByVal pszSrc As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ResUtilExpandEnvironmentStrings = ctypes.windll.resutils.ResUtilExpandEnvironmentStrings
ResUtilExpandEnvironmentStrings.restype = wintypes.LPWSTR
ResUtilExpandEnvironmentStrings.argtypes = [
wintypes.LPCWSTR, # pszSrc : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('RESUTILS.dll')
ResUtilExpandEnvironmentStrings = Fiddle::Function.new(
lib['ResUtilExpandEnvironmentStrings'],
[
Fiddle::TYPE_VOIDP, # pszSrc : LPCWSTR
],
Fiddle::TYPE_VOIDP)#[link(name = "resutils")]
extern "system" {
fn ResUtilExpandEnvironmentStrings(
pszSrc: *const u16 // LPCWSTR
) -> *mut u16;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("RESUTILS.dll", SetLastError = true)]
public static extern IntPtr ResUtilExpandEnvironmentStrings([MarshalAs(UnmanagedType.LPWStr)] string pszSrc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RESUTILS_ResUtilExpandEnvironmentStrings' -Namespace Win32 -PassThru
# $api::ResUtilExpandEnvironmentStrings(pszSrc)#uselib "RESUTILS.dll"
#func global ResUtilExpandEnvironmentStrings "ResUtilExpandEnvironmentStrings" sptr
; ResUtilExpandEnvironmentStrings pszSrc ; 戻り値は stat
; pszSrc : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "RESUTILS.dll"
#cfunc global ResUtilExpandEnvironmentStrings "ResUtilExpandEnvironmentStrings" wstr
; res = ResUtilExpandEnvironmentStrings(pszSrc)
; pszSrc : LPCWSTR -> "wstr"; LPWSTR ResUtilExpandEnvironmentStrings(LPCWSTR pszSrc)
#uselib "RESUTILS.dll"
#cfunc global ResUtilExpandEnvironmentStrings "ResUtilExpandEnvironmentStrings" wstr
; res = ResUtilExpandEnvironmentStrings(pszSrc)
; pszSrc : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
resutils = windows.NewLazySystemDLL("RESUTILS.dll")
procResUtilExpandEnvironmentStrings = resutils.NewProc("ResUtilExpandEnvironmentStrings")
)
// pszSrc (LPCWSTR)
r1, _, err := procResUtilExpandEnvironmentStrings.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSrc))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // LPWSTRfunction ResUtilExpandEnvironmentStrings(
pszSrc: PWideChar // LPCWSTR
): PWideChar; stdcall;
external 'RESUTILS.dll' name 'ResUtilExpandEnvironmentStrings';result := DllCall("RESUTILS\ResUtilExpandEnvironmentStrings"
, "WStr", pszSrc ; LPCWSTR
, "Ptr") ; return: LPWSTR●ResUtilExpandEnvironmentStrings(pszSrc) = DLL("RESUTILS.dll", "char* ResUtilExpandEnvironmentStrings(char*)")
# 呼び出し: ResUtilExpandEnvironmentStrings(pszSrc)
# pszSrc : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "resutils" fn ResUtilExpandEnvironmentStrings(
pszSrc: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) [*c]const u16;proc ResUtilExpandEnvironmentStrings(
pszSrc: WideCString # LPCWSTR
): WideCString {.importc: "ResUtilExpandEnvironmentStrings", stdcall, dynlib: "RESUTILS.dll".}pragma(lib, "resutils");
extern(Windows)
const(wchar)* ResUtilExpandEnvironmentStrings(
const(wchar)* pszSrc // LPCWSTR
);ccall((:ResUtilExpandEnvironmentStrings, "RESUTILS.dll"), stdcall, Cwstring,
(Cwstring,),
pszSrc)
# pszSrc : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
const uint16_t* ResUtilExpandEnvironmentStrings(
const uint16_t* pszSrc);
]]
local resutils = ffi.load("resutils")
-- resutils.ResUtilExpandEnvironmentStrings(pszSrc)
-- pszSrc : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('RESUTILS.dll');
const ResUtilExpandEnvironmentStrings = lib.func('__stdcall', 'ResUtilExpandEnvironmentStrings', 'void *', ['str16']);
// ResUtilExpandEnvironmentStrings(pszSrc)
// pszSrc : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RESUTILS.dll", {
ResUtilExpandEnvironmentStrings: { parameters: ["buffer"], result: "pointer" },
});
// lib.symbols.ResUtilExpandEnvironmentStrings(pszSrc)
// pszSrc : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
const uint16_t* ResUtilExpandEnvironmentStrings(
const uint16_t* pszSrc);
C, "RESUTILS.dll");
// $ffi->ResUtilExpandEnvironmentStrings(pszSrc);
// pszSrc : LPCWSTR
// 構造体/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 Resutils extends StdCallLibrary {
Resutils INSTANCE = Native.load("resutils", Resutils.class);
Pointer ResUtilExpandEnvironmentStrings(
WString pszSrc // LPCWSTR
);
}@[Link("resutils")]
lib LibRESUTILS
fun ResUtilExpandEnvironmentStrings = ResUtilExpandEnvironmentStrings(
pszSrc : UInt16* # LPCWSTR
) : UInt16*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ResUtilExpandEnvironmentStringsNative = Pointer<Utf16> Function(Pointer<Utf16>);
typedef ResUtilExpandEnvironmentStringsDart = Pointer<Utf16> Function(Pointer<Utf16>);
final ResUtilExpandEnvironmentStrings = DynamicLibrary.open('RESUTILS.dll')
.lookupFunction<ResUtilExpandEnvironmentStringsNative, ResUtilExpandEnvironmentStringsDart>('ResUtilExpandEnvironmentStrings');
// pszSrc : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ResUtilExpandEnvironmentStrings(
pszSrc: PWideChar // LPCWSTR
): PWideChar; stdcall;
external 'RESUTILS.dll' name 'ResUtilExpandEnvironmentStrings';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ResUtilExpandEnvironmentStrings"
c_ResUtilExpandEnvironmentStrings :: CWString -> IO CWString
-- pszSrc : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let resutilexpandenvironmentstrings =
foreign "ResUtilExpandEnvironmentStrings"
((ptr uint16_t) @-> returning (ptr uint16_t))
(* pszSrc : LPCWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library resutils (t "RESUTILS.dll"))
(cffi:use-foreign-library resutils)
(cffi:defcfun ("ResUtilExpandEnvironmentStrings" res-util-expand-environment-strings :convention :stdcall) (:string :encoding :utf-16le)
(psz-src (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ResUtilExpandEnvironmentStrings = Win32::API::More->new('RESUTILS',
'LPWSTR ResUtilExpandEnvironmentStrings(LPCWSTR pszSrc)');
# my $ret = $ResUtilExpandEnvironmentStrings->Call($pszSrc);
# pszSrc : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。