Win32 API 日本語リファレンス
ホームStorage.FileSystem › GetExpandedNameA

GetExpandedNameA

関数
圧縮ファイルの元のファイル名を取得する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

INT GetExpandedNameA(
    LPSTR lpszSource,
    LPSTR lpszBuffer
);

パラメーター

名前方向説明
lpszSourceLPSTRin圧縮されたファイルの名前です。
lpszBufferLPSTRout圧縮されたファイルの元の名前を受け取るバッファーへのポインターです。

戻り値の型: INT

公式ドキュメント

Lempel-Ziv アルゴリズムで圧縮されたファイルについて、その元のファイル名を取得します。(ANSI)

戻り値

関数が成功した場合、戻り値は 1 です。

関数が失敗した場合、戻り値は LZERROR_BADVALUE です。この関数には拡張エラー情報はありません。 GetLastError を呼び出さないでください。

注意 GetExpandedNameSetLastErrorSetLastErrorEx のいずれも呼び出しません。したがって、この関数の失敗はスレッドの最終エラー コードに影響しません。

解説(Remarks)

lpszBuffer パラメーターが指すバッファーの内容は、ファイルが /r オプションを使用して圧縮されていた場合は元のファイル名になります。/r オプションが使用されていなかった場合、この関数は lpszSource パラメーターの名前を lpszBuffer バッファーへ複製します。

Windows 8 および Windows Server 2012 では、この関数は次のテクノロジでサポートされています。

テクノロジ サポート
Server Message Block (SMB) 3.0 プロトコル はい
SMB 3.0 Transparent Failover (TFO) はい
SMB 3.0 with Scale-out File Shares (SO) はい
Cluster Shared Volume File System (CsvFS) はい
Resilient File System (ReFS) はい
メモ

lzexpand.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして GetExpandedName を定義します。エンコーディング非依存のエイリアスの使用を、エンコーディング非依存ではないコードと混在させると、コンパイル エラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

INT GetExpandedNameA(
    LPSTR lpszSource,
    LPSTR lpszBuffer
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern int GetExpandedNameA(
    [MarshalAs(UnmanagedType.LPStr)] string lpszSource,   // LPSTR
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpszBuffer   // LPSTR out
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetExpandedNameA(
    <MarshalAs(UnmanagedType.LPStr)> lpszSource As String,   ' LPSTR
    <MarshalAs(UnmanagedType.LPStr)> lpszBuffer As System.Text.StringBuilder   ' LPSTR out
) As Integer
End Function
' lpszSource : LPSTR
' lpszBuffer : LPSTR out
Declare PtrSafe Function GetExpandedNameA Lib "kernel32" ( _
    ByVal lpszSource As String, _
    ByVal lpszBuffer As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetExpandedNameA = ctypes.windll.kernel32.GetExpandedNameA
GetExpandedNameA.restype = ctypes.c_int
GetExpandedNameA.argtypes = [
    wintypes.LPCSTR,  # lpszSource : LPSTR
    wintypes.LPSTR,  # lpszBuffer : LPSTR out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetExpandedNameA = kernel32.NewProc("GetExpandedNameA")
)

// lpszSource (LPSTR), lpszBuffer (LPSTR out)
r1, _, err := procGetExpandedNameA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszSource))),
	uintptr(lpszBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function GetExpandedNameA(
  lpszSource: PAnsiChar;   // LPSTR
  lpszBuffer: PAnsiChar   // LPSTR out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetExpandedNameA';
result := DllCall("KERNEL32\GetExpandedNameA"
    , "AStr", lpszSource   ; LPSTR
    , "Ptr", lpszBuffer   ; LPSTR out
    , "Int")   ; return: INT
●GetExpandedNameA(lpszSource, lpszBuffer) = DLL("KERNEL32.dll", "int GetExpandedNameA(char*, char*)")
# 呼び出し: GetExpandedNameA(lpszSource, lpszBuffer)
# lpszSource : LPSTR -> "char*"
# lpszBuffer : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "kernel32" fn GetExpandedNameA(
    lpszSource: [*c]const u8, // LPSTR
    lpszBuffer: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) i32;
proc GetExpandedNameA(
    lpszSource: cstring,  # LPSTR
    lpszBuffer: ptr char  # LPSTR out
): int32 {.importc: "GetExpandedNameA", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int GetExpandedNameA(
    const(char)* lpszSource,   // LPSTR
    char* lpszBuffer   // LPSTR out
);
ccall((:GetExpandedNameA, "KERNEL32.dll"), stdcall, Int32,
      (Cstring, Ptr{UInt8}),
      lpszSource, lpszBuffer)
# lpszSource : LPSTR -> Cstring
# lpszBuffer : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetExpandedNameA(
    const char* lpszSource,
    char* lpszBuffer);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetExpandedNameA(lpszSource, lpszBuffer)
-- lpszSource : LPSTR
-- lpszBuffer : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetExpandedNameA = lib.func('__stdcall', 'GetExpandedNameA', 'int32_t', ['str', 'char *']);
// GetExpandedNameA(lpszSource, lpszBuffer)
// lpszSource : LPSTR -> 'str'
// lpszBuffer : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  GetExpandedNameA: { parameters: ["buffer", "buffer"], result: "i32" },
});
// lib.symbols.GetExpandedNameA(lpszSource, lpszBuffer)
// lpszSource : LPSTR -> "buffer"
// lpszBuffer : LPSTR out -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetExpandedNameA(
    const char* lpszSource,
    char* lpszBuffer);
C, "KERNEL32.dll");
// $ffi->GetExpandedNameA(lpszSource, lpszBuffer);
// lpszSource : LPSTR
// lpszBuffer : LPSTR 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.ASCII_OPTIONS);
    int GetExpandedNameA(
        String lpszSource,   // LPSTR
        byte[] lpszBuffer   // LPSTR out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun GetExpandedNameA = GetExpandedNameA(
    lpszSource : UInt8*,   # LPSTR
    lpszBuffer : UInt8*   # LPSTR out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetExpandedNameANative = Int32 Function(Pointer<Utf8>, Pointer<Utf8>);
typedef GetExpandedNameADart = int Function(Pointer<Utf8>, Pointer<Utf8>);
final GetExpandedNameA = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<GetExpandedNameANative, GetExpandedNameADart>('GetExpandedNameA');
// lpszSource : LPSTR -> Pointer<Utf8>
// lpszBuffer : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetExpandedNameA(
  lpszSource: PAnsiChar;   // LPSTR
  lpszBuffer: PAnsiChar   // LPSTR out
): Integer; stdcall;
  external 'KERNEL32.dll' name 'GetExpandedNameA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetExpandedNameA"
  c_GetExpandedNameA :: CString -> CString -> IO Int32
-- lpszSource : LPSTR -> CString
-- lpszBuffer : LPSTR out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getexpandednamea =
  foreign "GetExpandedNameA"
    (string @-> string @-> returning int32_t)
(* lpszSource : LPSTR -> string *)
(* lpszBuffer : LPSTR out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("GetExpandedNameA" get-expanded-name-a :convention :stdcall) :int32
  (lpsz-source :string)   ; LPSTR
  (lpsz-buffer :pointer))   ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetExpandedNameA = Win32::API::More->new('KERNEL32',
    'int GetExpandedNameA(LPCSTR lpszSource, LPSTR lpszBuffer)');
# my $ret = $GetExpandedNameA->Call($lpszSource, $lpszBuffer);
# lpszSource : LPSTR -> LPCSTR
# lpszBuffer : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い