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

SHSetLocalizedName

関数
パスにローカライズされた表示名を設定する。
DLLSHELL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT SHSetLocalizedName(
    LPCWSTR pszPath,
    LPCWSTR pszResModule,
    INT idsRes
);

パラメーター

名前方向
pszPathLPCWSTRin
pszResModuleLPCWSTRin
idsResINTin

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SHSetLocalizedName(
    LPCWSTR pszPath,
    LPCWSTR pszResModule,
    INT idsRes
);
[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern int SHSetLocalizedName(
    [MarshalAs(UnmanagedType.LPWStr)] string pszPath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszResModule,   // LPCWSTR
    int idsRes   // INT
);
<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHSetLocalizedName(
    <MarshalAs(UnmanagedType.LPWStr)> pszPath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszResModule As String,   ' LPCWSTR
    idsRes As Integer   ' INT
) As Integer
End Function
' pszPath : LPCWSTR
' pszResModule : LPCWSTR
' idsRes : INT
Declare PtrSafe Function SHSetLocalizedName Lib "shell32" ( _
    ByVal pszPath As LongPtr, _
    ByVal pszResModule As LongPtr, _
    ByVal idsRes As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SHSetLocalizedName = ctypes.windll.shell32.SHSetLocalizedName
SHSetLocalizedName.restype = ctypes.c_int
SHSetLocalizedName.argtypes = [
    wintypes.LPCWSTR,  # pszPath : LPCWSTR
    wintypes.LPCWSTR,  # pszResModule : LPCWSTR
    ctypes.c_int,  # idsRes : INT
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHSetLocalizedName = Fiddle::Function.new(
  lib['SHSetLocalizedName'],
  [
    Fiddle::TYPE_VOIDP,  # pszPath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszResModule : LPCWSTR
    Fiddle::TYPE_INT,  # idsRes : INT
  ],
  Fiddle::TYPE_INT)
#[link(name = "shell32")]
extern "system" {
    fn SHSetLocalizedName(
        pszPath: *const u16,  // LPCWSTR
        pszResModule: *const u16,  // LPCWSTR
        idsRes: i32  // INT
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SHELL32.dll")]
public static extern int SHSetLocalizedName([MarshalAs(UnmanagedType.LPWStr)] string pszPath, [MarshalAs(UnmanagedType.LPWStr)] string pszResModule, int idsRes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHSetLocalizedName' -Namespace Win32 -PassThru
# $api::SHSetLocalizedName(pszPath, pszResModule, idsRes)
#uselib "SHELL32.dll"
#func global SHSetLocalizedName "SHSetLocalizedName" sptr, sptr, sptr
; SHSetLocalizedName pszPath, pszResModule, idsRes   ; 戻り値は stat
; pszPath : LPCWSTR -> "sptr"
; pszResModule : LPCWSTR -> "sptr"
; idsRes : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global SHSetLocalizedName "SHSetLocalizedName" wstr, wstr, int
; res = SHSetLocalizedName(pszPath, pszResModule, idsRes)
; pszPath : LPCWSTR -> "wstr"
; pszResModule : LPCWSTR -> "wstr"
; idsRes : INT -> "int"
; HRESULT SHSetLocalizedName(LPCWSTR pszPath, LPCWSTR pszResModule, INT idsRes)
#uselib "SHELL32.dll"
#cfunc global SHSetLocalizedName "SHSetLocalizedName" wstr, wstr, int
; res = SHSetLocalizedName(pszPath, pszResModule, idsRes)
; pszPath : LPCWSTR -> "wstr"
; pszResModule : LPCWSTR -> "wstr"
; idsRes : INT -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHSetLocalizedName = shell32.NewProc("SHSetLocalizedName")
)

// pszPath (LPCWSTR), pszResModule (LPCWSTR), idsRes (INT)
r1, _, err := procSHSetLocalizedName.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszResModule))),
	uintptr(idsRes),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SHSetLocalizedName(
  pszPath: PWideChar;   // LPCWSTR
  pszResModule: PWideChar;   // LPCWSTR
  idsRes: Integer   // INT
): Integer; stdcall;
  external 'SHELL32.dll' name 'SHSetLocalizedName';
result := DllCall("SHELL32\SHSetLocalizedName"
    , "WStr", pszPath   ; LPCWSTR
    , "WStr", pszResModule   ; LPCWSTR
    , "Int", idsRes   ; INT
    , "Int")   ; return: HRESULT
●SHSetLocalizedName(pszPath, pszResModule, idsRes) = DLL("SHELL32.dll", "int SHSetLocalizedName(char*, char*, int)")
# 呼び出し: SHSetLocalizedName(pszPath, pszResModule, idsRes)
# pszPath : LPCWSTR -> "char*"
# pszResModule : LPCWSTR -> "char*"
# idsRes : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。