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

SHLoadIndirectString

関数
リソース参照形式の間接文字列を読み込んで展開する。
DLLSHLWAPI.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT SHLoadIndirectString(
    LPCWSTR pszSource,
    LPWSTR pszOutBuf,
    DWORD cchOutBuf,
    void** ppvReserved   // optional
);

パラメーター

名前方向説明
pszSourceLPCWSTRinリソースの取得元となる間接文字列を格納したバッファへのポインター。この文字列は '@' 記号で始まり、解説セクションで説明されている形式のいずれかを使用する必要があります。この関数は '@' 記号で始まらない文字列も正常に受け付けますが、その場合、文字列は変更されずにそのまま pszOutBuf に渡されます。
pszOutBufLPWSTRoutこの関数が正常に終了したときに、テキストリソースを受け取るバッファへのポインター。pszOutBufpszSource は同じバッファを指していてもかまいません。その場合、元の文字列は上書きされます。
cchOutBufDWORDinpszOutBuf が指すバッファのサイズ(文字数単位)。
ppvReservedvoid**optional使用されません。NULL を設定してください。

戻り値の型: HRESULT

公式ドキュメント

間接文字列('@' 記号で始まる文字列)の形式で指定されたリソースから、指定したテキストリソースを取り出します。

戻り値

Type: HRESULT

この関数が成功した場合は S_OK を返します。それ以外の場合は HRESULT エラーコードを返します。

解説(Remarks)

間接文字列はいくつかの形式で指定でき、それぞれに独自の解釈があります。

文字列が間接文字列でない場合、その文字列は変更されずに pszOutBuf に直接コピーされ、関数は S_OK を返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // HRESULT
function 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 を使用。