SHLoadIndirectString
関数シグネチャ
// SHLWAPI.dll
#include <windows.h>
HRESULT SHLoadIndirectString(
LPCWSTR pszSource,
LPWSTR pszOutBuf,
DWORD cchOutBuf,
void** ppvReserved // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pszSource | LPCWSTR | in | リソースの取得元となる間接文字列を格納したバッファへのポインター。この文字列は '@' 記号で始まり、解説セクションで説明されている形式のいずれかを使用する必要があります。この関数は '@' 記号で始まらない文字列も正常に受け付けますが、その場合、文字列は変更されずにそのまま pszOutBuf に渡されます。 |
| pszOutBuf | LPWSTR | out | この関数が正常に終了したときに、テキストリソースを受け取るバッファへのポインター。pszOutBuf と pszSource は同じバッファを指していてもかまいません。その場合、元の文字列は上書きされます。 |
| cchOutBuf | DWORD | in | pszOutBuf が指すバッファのサイズ(文字数単位)。 |
| ppvReserved | void** | optional | 使用されません。NULL を設定してください。 |
戻り値の型: HRESULT
公式ドキュメント
間接文字列('@' 記号で始まる文字列)の形式で指定されたリソースから、指定したテキストリソースを取り出します。
戻り値
Type: HRESULT
この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。
解説(Remarks)
間接文字列はいくつかの形式で指定でき、それぞれに独自の解釈があります。
- ファイル名とリソース ID
``` syntax
@filename,resource
```
resource 値をロケーターとして使用し、指定したファイルから文字列が取り出されます。リソース値が 0 以上の場合、その数値はバイナリファイル内の文字列のインデックスになります。数値が負の場合は、リソース ID になります。取得された文字列は出力バッファにコピーされ、関数は S_OK を返します。
- バージョン修飾子付きのファイル名とリソース ID
``` syntax
@filename,resource;v2
```
この形式は、リソースが変更されたものの、古いリソースと同じインデックスまたは ID を引き続き使用する場合に利用できます。バージョン修飾子がない場合、Multilingual User Interface (MUI) キャッシュはリソースが変更されたことを認識せず、更新を行いません。バージョン修飾子を付加すると、その値は新しいリソースとして認識され、キャッシュに追加されます。なお、新しいリソースには新しい ID またはインデックスを使用することを推奨します。バージョン修飾子は、それが不可能な場合にのみ使用してください。
- PRI ファイルのパスとリソース ID
``` syntax
@{PRIFilepath?resource}
```
Package Resource Index (PRI) は Windows 8 で導入されたバイナリ形式で、インデックス化されたリソースまたはリソースへの参照を格納します。.pri ファイルはアプリのパッケージの一部としてバンドルされます。.pri ファイルの詳細については、Windows ストアアプリでのリソースの作成と取得を参照してください。
resource をロケーターとして使用し、指定した .pri ファイルから文字列が取り出されます。取得された文字列は出力バッファにコピーされ、関数は S_OK を返します。文字列は現在の Shell 環境または ResourceContext に基づいて取り出されます。
この種類の間接文字列の例を次に示します。
@{C:\Program Files\WindowsApps\Microsoft.Camera_6.2.8376.0_x64__8wekyb3d8bbwe\resources.pri? ms-resource://Microsoft.Camera/resources/manifestAppDescription} - パッケージ名とリソース ID
``` syntax
@{PackageFullName?resource}
```
resource をロケーターとして使用し、PackageFullName で識別されるパッケージのアプリのルートディレクトリに格納された Resources.pri ファイルから文字列が取り出されます。取得された文字列は出力バッファにコピーされ、関数は S_OK を返します。文字列はアプリの環境または ResourceContext に基づいて取り出されます。
注意 この文字列は、現在のユーザー向けにインストールされているパッケージを参照している必要があります。そうでない場合、呼び出しは失敗します。この種類の間接文字列の例を次に示します。この例では、参照名は完全修飾されていますが、名前空間(例: "resources")は含まれていません。デプロイメントスタックは名前を展開し、すべての名前空間でその名前を検索します。@{Microsoft.Camera_6.2.8376.0_x64__8wekyb3d8bbwe? ms-resource://Microsoft.Camera/manifestAppDescription}次の例では、完全修飾された参照名が、検索を限定するための名前空間を指定しています。
@{Microsoft.Camera_6.2.8376.0_x64__8wekyb3d8bbwe? ms-resource://Microsoft.Camera/resources/manifestAppDescription}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHLWAPI.dll
#include <windows.h>
HRESULT SHLoadIndirectString(
LPCWSTR pszSource,
LPWSTR pszOutBuf,
DWORD cchOutBuf,
void** ppvReserved // optional
);[DllImport("SHLWAPI.dll", ExactSpelling = true)]
static extern int SHLoadIndirectString(
[MarshalAs(UnmanagedType.LPWStr)] string pszSource, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszOutBuf, // LPWSTR out
uint cchOutBuf, // DWORD
IntPtr ppvReserved // void** optional
);<DllImport("SHLWAPI.dll", ExactSpelling:=True)>
Public Shared Function SHLoadIndirectString(
<MarshalAs(UnmanagedType.LPWStr)> pszSource As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pszOutBuf As System.Text.StringBuilder, ' LPWSTR out
cchOutBuf As UInteger, ' DWORD
ppvReserved As IntPtr ' void** optional
) As Integer
End Function' pszSource : LPCWSTR
' pszOutBuf : LPWSTR out
' cchOutBuf : DWORD
' ppvReserved : void** optional
Declare PtrSafe Function SHLoadIndirectString Lib "shlwapi" ( _
ByVal pszSource As LongPtr, _
ByVal pszOutBuf As LongPtr, _
ByVal cchOutBuf As Long, _
ByVal ppvReserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHLoadIndirectString = ctypes.windll.shlwapi.SHLoadIndirectString
SHLoadIndirectString.restype = ctypes.c_int
SHLoadIndirectString.argtypes = [
wintypes.LPCWSTR, # pszSource : LPCWSTR
wintypes.LPWSTR, # pszOutBuf : LPWSTR out
wintypes.DWORD, # cchOutBuf : DWORD
ctypes.c_void_p, # ppvReserved : void** optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
SHLoadIndirectString = Fiddle::Function.new(
lib['SHLoadIndirectString'],
[
Fiddle::TYPE_VOIDP, # pszSource : LPCWSTR
Fiddle::TYPE_VOIDP, # pszOutBuf : LPWSTR out
-Fiddle::TYPE_INT, # cchOutBuf : DWORD
Fiddle::TYPE_VOIDP, # ppvReserved : void** optional
],
Fiddle::TYPE_INT)#[link(name = "shlwapi")]
extern "system" {
fn SHLoadIndirectString(
pszSource: *const u16, // LPCWSTR
pszOutBuf: *mut u16, // LPWSTR out
cchOutBuf: u32, // DWORD
ppvReserved: *mut *mut () // void** optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHLWAPI.dll")]
public static extern int SHLoadIndirectString([MarshalAs(UnmanagedType.LPWStr)] string pszSource, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszOutBuf, uint cchOutBuf, IntPtr ppvReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_SHLoadIndirectString' -Namespace Win32 -PassThru
# $api::SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved)#uselib "SHLWAPI.dll"
#func global SHLoadIndirectString "SHLoadIndirectString" sptr, sptr, sptr, sptr
; SHLoadIndirectString pszSource, varptr(pszOutBuf), cchOutBuf, ppvReserved ; 戻り値は stat
; pszSource : LPCWSTR -> "sptr"
; pszOutBuf : LPWSTR out -> "sptr"
; cchOutBuf : DWORD -> "sptr"
; ppvReserved : void** optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHLWAPI.dll" #cfunc global SHLoadIndirectString "SHLoadIndirectString" wstr, var, int, sptr ; res = SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved) ; pszSource : LPCWSTR -> "wstr" ; pszOutBuf : LPWSTR out -> "var" ; cchOutBuf : DWORD -> "int" ; ppvReserved : void** optional -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHLWAPI.dll" #cfunc global SHLoadIndirectString "SHLoadIndirectString" wstr, sptr, int, sptr ; res = SHLoadIndirectString(pszSource, varptr(pszOutBuf), cchOutBuf, ppvReserved) ; pszSource : LPCWSTR -> "wstr" ; pszOutBuf : LPWSTR out -> "sptr" ; cchOutBuf : DWORD -> "int" ; ppvReserved : void** optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HRESULT SHLoadIndirectString(LPCWSTR pszSource, LPWSTR pszOutBuf, DWORD cchOutBuf, void** ppvReserved) #uselib "SHLWAPI.dll" #cfunc global SHLoadIndirectString "SHLoadIndirectString" wstr, var, int, intptr ; res = SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved) ; pszSource : LPCWSTR -> "wstr" ; pszOutBuf : LPWSTR out -> "var" ; cchOutBuf : DWORD -> "int" ; ppvReserved : void** optional -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT SHLoadIndirectString(LPCWSTR pszSource, LPWSTR pszOutBuf, DWORD cchOutBuf, void** ppvReserved) #uselib "SHLWAPI.dll" #cfunc global SHLoadIndirectString "SHLoadIndirectString" wstr, intptr, int, intptr ; res = SHLoadIndirectString(pszSource, varptr(pszOutBuf), cchOutBuf, ppvReserved) ; pszSource : LPCWSTR -> "wstr" ; pszOutBuf : LPWSTR out -> "intptr" ; cchOutBuf : DWORD -> "int" ; ppvReserved : void** optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procSHLoadIndirectString = shlwapi.NewProc("SHLoadIndirectString")
)
// pszSource (LPCWSTR), pszOutBuf (LPWSTR out), cchOutBuf (DWORD), ppvReserved (void** optional)
r1, _, err := procSHLoadIndirectString.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszSource))),
uintptr(pszOutBuf),
uintptr(cchOutBuf),
uintptr(ppvReserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SHLoadIndirectString(
pszSource: PWideChar; // LPCWSTR
pszOutBuf: PWideChar; // LPWSTR out
cchOutBuf: DWORD; // DWORD
ppvReserved: Pointer // void** optional
): Integer; stdcall;
external 'SHLWAPI.dll' name 'SHLoadIndirectString';result := DllCall("SHLWAPI\SHLoadIndirectString"
, "WStr", pszSource ; LPCWSTR
, "Ptr", pszOutBuf ; LPWSTR out
, "UInt", cchOutBuf ; DWORD
, "Ptr", ppvReserved ; void** optional
, "Int") ; return: HRESULT●SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved) = DLL("SHLWAPI.dll", "int SHLoadIndirectString(char*, char*, dword, void*)")
# 呼び出し: SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved)
# pszSource : LPCWSTR -> "char*"
# pszOutBuf : LPWSTR out -> "char*"
# cchOutBuf : DWORD -> "dword"
# ppvReserved : void** optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shlwapi" fn SHLoadIndirectString(
pszSource: [*c]const u16, // LPCWSTR
pszOutBuf: [*c]u16, // LPWSTR out
cchOutBuf: u32, // DWORD
ppvReserved: ?*anyopaque // void** optional
) callconv(std.os.windows.WINAPI) i32;proc SHLoadIndirectString(
pszSource: WideCString, # LPCWSTR
pszOutBuf: ptr uint16, # LPWSTR out
cchOutBuf: uint32, # DWORD
ppvReserved: pointer # void** optional
): int32 {.importc: "SHLoadIndirectString", stdcall, dynlib: "SHLWAPI.dll".}pragma(lib, "shlwapi");
extern(Windows)
int SHLoadIndirectString(
const(wchar)* pszSource, // LPCWSTR
wchar* pszOutBuf, // LPWSTR out
uint cchOutBuf, // DWORD
void** ppvReserved // void** optional
);ccall((:SHLoadIndirectString, "SHLWAPI.dll"), stdcall, Int32,
(Cwstring, Ptr{UInt16}, UInt32, Ptr{Cvoid}),
pszSource, pszOutBuf, cchOutBuf, ppvReserved)
# pszSource : LPCWSTR -> Cwstring
# pszOutBuf : LPWSTR out -> Ptr{UInt16}
# cchOutBuf : DWORD -> UInt32
# ppvReserved : void** optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SHLoadIndirectString(
const uint16_t* pszSource,
uint16_t* pszOutBuf,
uint32_t cchOutBuf,
void** ppvReserved);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved)
-- pszSource : LPCWSTR
-- pszOutBuf : LPWSTR out
-- cchOutBuf : DWORD
-- ppvReserved : void** optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const SHLoadIndirectString = lib.func('__stdcall', 'SHLoadIndirectString', 'int32_t', ['str16', 'uint16_t *', 'uint32_t', 'void *']);
// SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved)
// pszSource : LPCWSTR -> 'str16'
// pszOutBuf : LPWSTR out -> 'uint16_t *'
// cchOutBuf : DWORD -> 'uint32_t'
// ppvReserved : void** optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHLWAPI.dll", {
SHLoadIndirectString: { parameters: ["buffer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved)
// pszSource : LPCWSTR -> "buffer"
// pszOutBuf : LPWSTR out -> "buffer"
// cchOutBuf : DWORD -> "u32"
// ppvReserved : void** optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SHLoadIndirectString(
const uint16_t* pszSource,
uint16_t* pszOutBuf,
uint32_t cchOutBuf,
void** ppvReserved);
C, "SHLWAPI.dll");
// $ffi->SHLoadIndirectString(pszSource, pszOutBuf, cchOutBuf, ppvReserved);
// pszSource : LPCWSTR
// pszOutBuf : LPWSTR out
// cchOutBuf : DWORD
// ppvReserved : void** optional
// 構造体/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 Shlwapi extends StdCallLibrary {
Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class);
int SHLoadIndirectString(
WString pszSource, // LPCWSTR
char[] pszOutBuf, // LPWSTR out
int cchOutBuf, // DWORD
Pointer ppvReserved // void** optional
);
}@[Link("shlwapi")]
lib LibSHLWAPI
fun SHLoadIndirectString = SHLoadIndirectString(
pszSource : UInt16*, # LPCWSTR
pszOutBuf : UInt16*, # LPWSTR out
cchOutBuf : UInt32, # DWORD
ppvReserved : Void** # void** optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHLoadIndirectStringNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Void>);
typedef SHLoadIndirectStringDart = int Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Void>);
final SHLoadIndirectString = DynamicLibrary.open('SHLWAPI.dll')
.lookupFunction<SHLoadIndirectStringNative, SHLoadIndirectStringDart>('SHLoadIndirectString');
// pszSource : LPCWSTR -> Pointer<Utf16>
// pszOutBuf : LPWSTR out -> Pointer<Utf16>
// cchOutBuf : DWORD -> Uint32
// ppvReserved : void** optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHLoadIndirectString(
pszSource: PWideChar; // LPCWSTR
pszOutBuf: PWideChar; // LPWSTR out
cchOutBuf: DWORD; // DWORD
ppvReserved: Pointer // void** optional
): Integer; stdcall;
external 'SHLWAPI.dll' name 'SHLoadIndirectString';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHLoadIndirectString"
c_SHLoadIndirectString :: CWString -> CWString -> Word32 -> Ptr () -> IO Int32
-- pszSource : LPCWSTR -> CWString
-- pszOutBuf : LPWSTR out -> CWString
-- cchOutBuf : DWORD -> Word32
-- ppvReserved : void** optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shloadindirectstring =
foreign "SHLoadIndirectString"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* pszSource : LPCWSTR -> (ptr uint16_t) *)
(* pszOutBuf : LPWSTR out -> (ptr uint16_t) *)
(* cchOutBuf : DWORD -> uint32_t *)
(* ppvReserved : void** optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)
(cffi:defcfun ("SHLoadIndirectString" shload-indirect-string :convention :stdcall) :int32
(psz-source (:string :encoding :utf-16le)) ; LPCWSTR
(psz-out-buf :pointer) ; LPWSTR out
(cch-out-buf :uint32) ; DWORD
(ppv-reserved :pointer)) ; void** optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHLoadIndirectString = Win32::API::More->new('SHLWAPI',
'int SHLoadIndirectString(LPCWSTR pszSource, LPWSTR pszOutBuf, DWORD cchOutBuf, LPVOID ppvReserved)');
# my $ret = $SHLoadIndirectString->Call($pszSource, $pszOutBuf, $cchOutBuf, $ppvReserved);
# pszSource : LPCWSTR -> LPCWSTR
# pszOutBuf : LPWSTR out -> LPWSTR
# cchOutBuf : DWORD -> DWORD
# ppvReserved : void** optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。