ホーム › Storage.FileSystem › GetExpandedNameW
GetExpandedNameW
関数圧縮ファイルの元のファイル名を取得する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
INT GetExpandedNameW(
LPWSTR lpszSource,
LPWSTR lpszBuffer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpszSource | LPWSTR | in | 圧縮されたファイルの名前。 |
| lpszBuffer | LPWSTR | out | 圧縮されたファイルの元の名前を受け取るバッファーへのポインター。 |
戻り値の型: INT
公式ドキュメント
Lempel-Ziv アルゴリズムで圧縮されたファイルについて、その元の名前を取得します。(Unicode)
戻り値
関数が成功した場合、戻り値は 1 です。
関数が失敗した場合、戻り値は LZERROR_BADVALUE です。この関数には拡張エラー情報はありません。 GetLastError を呼び出さないでください。
注意 GetExpandedName は
SetLastError も
SetLastErrorEx も呼び出しません。そのため、この関数の失敗はスレッドの最終エラーコードに影響しません。
解説(Remarks)
lpszBuffer パラメーターが指すバッファーの内容は、ファイルが /r オプションを使用して圧縮された場合は元のファイル名になります。/r オプションが使用されなかった場合、この関数は lpszSource パラメーターの名前を lpszBuffer バッファーに複製します。
Windows 8 および Windows Server 2012 では、この関数は次のテクノロジでサポートされています。
| テクノロジ | サポート |
|---|---|
| Server Message Block (SMB) 3.0 プロトコル | はい |
| SMB 3.0 トランスペアレント フェールオーバー (TFO) | はい |
| SMB 3.0 スケールアウト ファイル共有 (SO) | はい |
| クラスター共有ボリューム ファイル システム (CsvFS) | はい |
| 回復性ファイル システム (ReFS) | はい |
メモ
lzexpand.h ヘッダーは GetExpandedName をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング ニュートラルなエイリアスの使用を、エンコーディング ニュートラルでないコードと混在させると、不一致が生じ、コンパイル エラーや実行時エラーの原因となる可能性があります。詳細については、関数プロトタイプの規約を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
INT GetExpandedNameW(
LPWSTR lpszSource,
LPWSTR lpszBuffer
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern int GetExpandedNameW(
[MarshalAs(UnmanagedType.LPWStr)] string lpszSource, // LPWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszBuffer // LPWSTR out
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetExpandedNameW(
<MarshalAs(UnmanagedType.LPWStr)> lpszSource As String, ' LPWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpszBuffer As System.Text.StringBuilder ' LPWSTR out
) As Integer
End Function' lpszSource : LPWSTR
' lpszBuffer : LPWSTR out
Declare PtrSafe Function GetExpandedNameW Lib "kernel32" ( _
ByVal lpszSource As LongPtr, _
ByVal lpszBuffer As LongPtr) 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
GetExpandedNameW = ctypes.windll.kernel32.GetExpandedNameW
GetExpandedNameW.restype = ctypes.c_int
GetExpandedNameW.argtypes = [
wintypes.LPCWSTR, # lpszSource : LPWSTR
wintypes.LPWSTR, # lpszBuffer : LPWSTR out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetExpandedNameW = Fiddle::Function.new(
lib['GetExpandedNameW'],
[
Fiddle::TYPE_VOIDP, # lpszSource : LPWSTR
Fiddle::TYPE_VOIDP, # lpszBuffer : LPWSTR out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn GetExpandedNameW(
lpszSource: *mut u16, // LPWSTR
lpszBuffer: *mut u16 // LPWSTR out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int GetExpandedNameW([MarshalAs(UnmanagedType.LPWStr)] string lpszSource, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpszBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetExpandedNameW' -Namespace Win32 -PassThru
# $api::GetExpandedNameW(lpszSource, lpszBuffer)#uselib "KERNEL32.dll"
#func global GetExpandedNameW "GetExpandedNameW" wptr, wptr
; GetExpandedNameW lpszSource, varptr(lpszBuffer) ; 戻り値は stat
; lpszSource : LPWSTR -> "wptr"
; lpszBuffer : LPWSTR out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global GetExpandedNameW "GetExpandedNameW" wstr, var ; res = GetExpandedNameW(lpszSource, lpszBuffer) ; lpszSource : LPWSTR -> "wstr" ; lpszBuffer : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global GetExpandedNameW "GetExpandedNameW" wstr, sptr ; res = GetExpandedNameW(lpszSource, varptr(lpszBuffer)) ; lpszSource : LPWSTR -> "wstr" ; lpszBuffer : LPWSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT GetExpandedNameW(LPWSTR lpszSource, LPWSTR lpszBuffer) #uselib "KERNEL32.dll" #cfunc global GetExpandedNameW "GetExpandedNameW" wstr, var ; res = GetExpandedNameW(lpszSource, lpszBuffer) ; lpszSource : LPWSTR -> "wstr" ; lpszBuffer : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT GetExpandedNameW(LPWSTR lpszSource, LPWSTR lpszBuffer) #uselib "KERNEL32.dll" #cfunc global GetExpandedNameW "GetExpandedNameW" wstr, intptr ; res = GetExpandedNameW(lpszSource, varptr(lpszBuffer)) ; lpszSource : LPWSTR -> "wstr" ; lpszBuffer : LPWSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetExpandedNameW = kernel32.NewProc("GetExpandedNameW")
)
// lpszSource (LPWSTR), lpszBuffer (LPWSTR out)
r1, _, err := procGetExpandedNameW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszSource))),
uintptr(lpszBuffer),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetExpandedNameW(
lpszSource: PWideChar; // LPWSTR
lpszBuffer: PWideChar // LPWSTR out
): Integer; stdcall;
external 'KERNEL32.dll' name 'GetExpandedNameW';result := DllCall("KERNEL32\GetExpandedNameW"
, "WStr", lpszSource ; LPWSTR
, "Ptr", lpszBuffer ; LPWSTR out
, "Int") ; return: INT●GetExpandedNameW(lpszSource, lpszBuffer) = DLL("KERNEL32.dll", "int GetExpandedNameW(char*, char*)")
# 呼び出し: GetExpandedNameW(lpszSource, lpszBuffer)
# lpszSource : LPWSTR -> "char*"
# lpszBuffer : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "kernel32" fn GetExpandedNameW(
lpszSource: [*c]const u16, // LPWSTR
lpszBuffer: [*c]u16 // LPWSTR out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GetExpandedNameW(
lpszSource: WideCString, # LPWSTR
lpszBuffer: ptr uint16 # LPWSTR out
): int32 {.importc: "GetExpandedNameW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "kernel32");
extern(Windows)
int GetExpandedNameW(
const(wchar)* lpszSource, // LPWSTR
wchar* lpszBuffer // LPWSTR out
);ccall((:GetExpandedNameW, "KERNEL32.dll"), stdcall, Int32,
(Cwstring, Ptr{UInt16}),
lpszSource, lpszBuffer)
# lpszSource : LPWSTR -> Cwstring
# lpszBuffer : LPWSTR out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t GetExpandedNameW(
const uint16_t* lpszSource,
uint16_t* lpszBuffer);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetExpandedNameW(lpszSource, lpszBuffer)
-- lpszSource : LPWSTR
-- lpszBuffer : LPWSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetExpandedNameW = lib.func('__stdcall', 'GetExpandedNameW', 'int32_t', ['str16', 'uint16_t *']);
// GetExpandedNameW(lpszSource, lpszBuffer)
// lpszSource : LPWSTR -> 'str16'
// lpszBuffer : LPWSTR out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetExpandedNameW: { parameters: ["buffer", "buffer"], result: "i32" },
});
// lib.symbols.GetExpandedNameW(lpszSource, lpszBuffer)
// lpszSource : LPWSTR -> "buffer"
// lpszBuffer : LPWSTR out -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetExpandedNameW(
const uint16_t* lpszSource,
uint16_t* lpszBuffer);
C, "KERNEL32.dll");
// $ffi->GetExpandedNameW(lpszSource, lpszBuffer);
// lpszSource : LPWSTR
// lpszBuffer : LPWSTR out
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
int GetExpandedNameW(
WString lpszSource, // LPWSTR
char[] lpszBuffer // LPWSTR out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("kernel32")]
lib LibKERNEL32
fun GetExpandedNameW = GetExpandedNameW(
lpszSource : UInt16*, # LPWSTR
lpszBuffer : UInt16* # LPWSTR out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetExpandedNameWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>);
typedef GetExpandedNameWDart = int Function(Pointer<Utf16>, Pointer<Utf16>);
final GetExpandedNameW = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetExpandedNameWNative, GetExpandedNameWDart>('GetExpandedNameW');
// lpszSource : LPWSTR -> Pointer<Utf16>
// lpszBuffer : LPWSTR out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetExpandedNameW(
lpszSource: PWideChar; // LPWSTR
lpszBuffer: PWideChar // LPWSTR out
): Integer; stdcall;
external 'KERNEL32.dll' name 'GetExpandedNameW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetExpandedNameW"
c_GetExpandedNameW :: CWString -> CWString -> IO Int32
-- lpszSource : LPWSTR -> CWString
-- lpszBuffer : LPWSTR out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getexpandednamew =
foreign "GetExpandedNameW"
((ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* lpszSource : LPWSTR -> (ptr uint16_t) *)
(* lpszBuffer : LPWSTR out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetExpandedNameW" get-expanded-name-w :convention :stdcall) :int32
(lpsz-source (:string :encoding :utf-16le)) ; LPWSTR
(lpsz-buffer :pointer)) ; LPWSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetExpandedNameW = Win32::API::More->new('KERNEL32',
'int GetExpandedNameW(LPCWSTR lpszSource, LPWSTR lpszBuffer)');
# my $ret = $GetExpandedNameW->Call($lpszSource, $lpszBuffer);
# lpszSource : LPWSTR -> LPCWSTR
# lpszBuffer : LPWSTR out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f GetExpandedNameA (ANSI版) — 圧縮ファイルの元のファイル名を取得する(ANSI版)。