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

PathGetShortPath

関数
長いパスを短い8.3形式のパスに変換する。
DLLSHELL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SHELL32.dll
#include <windows.h>

void PathGetShortPath(
    LPWSTR pszLongPath
);

パラメーター

名前方向
pszLongPathLPWSTRinout

戻り値の型: void

各言語での呼び出し定義

// SHELL32.dll
#include <windows.h>

void PathGetShortPath(
    LPWSTR pszLongPath
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern void PathGetShortPath(
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszLongPath   // LPWSTR in/out
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Sub PathGetShortPath(
    <MarshalAs(UnmanagedType.LPWStr)> pszLongPath As System.Text.StringBuilder   ' LPWSTR in/out
)
End Sub
' pszLongPath : LPWSTR in/out
Declare PtrSafe Sub PathGetShortPath Lib "shell32" ( _
    ByVal pszLongPath As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PathGetShortPath = ctypes.windll.shell32.PathGetShortPath
PathGetShortPath.restype = None
PathGetShortPath.argtypes = [
    wintypes.LPWSTR,  # pszLongPath : LPWSTR in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
PathGetShortPath = Fiddle::Function.new(
  lib['PathGetShortPath'],
  [
    Fiddle::TYPE_VOIDP,  # pszLongPath : LPWSTR in/out
  ],
  Fiddle::TYPE_VOID)
#[link(name = "shell32")]
extern "system" {
    fn PathGetShortPath(
        pszLongPath: *mut u16  // LPWSTR in/out
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern void PathGetShortPath([MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszLongPath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_PathGetShortPath' -Namespace Win32 -PassThru
# $api::PathGetShortPath(pszLongPath)
#uselib "SHELL32.dll"
#func global PathGetShortPath "PathGetShortPath" sptr
; PathGetShortPath varptr(pszLongPath)
; pszLongPath : LPWSTR in/out -> "sptr"
出力引数:
#uselib "SHELL32.dll"
#func global PathGetShortPath "PathGetShortPath" var
; PathGetShortPath pszLongPath
; pszLongPath : LPWSTR in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void PathGetShortPath(LPWSTR pszLongPath)
#uselib "SHELL32.dll"
#func global PathGetShortPath "PathGetShortPath" var
; PathGetShortPath pszLongPath
; pszLongPath : LPWSTR in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procPathGetShortPath = shell32.NewProc("PathGetShortPath")
)

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