ホーム › System.ClrHosting › LoadStringRCEx
LoadStringRCEx
関数ロケールを指定してリソースIDから文字列リソースを読み込む。
シグネチャ
// MSCorEE.dll
#include <windows.h>
HRESULT LoadStringRCEx(
DWORD lcid,
DWORD iResouceID,
LPWSTR szBuffer,
INT iMax,
INT bQuiet,
INT* pcwchUsed
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lcid | DWORD | in | 文字列をロードするロケール ID(LCID)。 |
| iResouceID | DWORD | in | ロードする文字列リソースの ID。 |
| szBuffer | LPWSTR | out | ロードした文字列を受け取る出力バッファ。Unicode 文字列で返される。 |
| iMax | INT | in | szBuffer の最大文字数。 |
| bQuiet | INT | in | エラー時にメッセージ表示を抑制するか。非ゼロで抑制する。 |
| pcwchUsed | INT* | inout | 実際に使用された文字数を受け取る出力ポインタ。NULL 可。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// MSCorEE.dll
#include <windows.h>
HRESULT LoadStringRCEx(
DWORD lcid,
DWORD iResouceID,
LPWSTR szBuffer,
INT iMax,
INT bQuiet,
INT* pcwchUsed
);[DllImport("MSCorEE.dll", ExactSpelling = true)]
static extern int LoadStringRCEx(
uint lcid, // DWORD
uint iResouceID, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szBuffer, // LPWSTR out
int iMax, // INT
int bQuiet, // INT
ref int pcwchUsed // INT* in/out
);<DllImport("MSCorEE.dll", ExactSpelling:=True)>
Public Shared Function LoadStringRCEx(
lcid As UInteger, ' DWORD
iResouceID As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> szBuffer As System.Text.StringBuilder, ' LPWSTR out
iMax As Integer, ' INT
bQuiet As Integer, ' INT
ByRef pcwchUsed As Integer ' INT* in/out
) As Integer
End Function' lcid : DWORD
' iResouceID : DWORD
' szBuffer : LPWSTR out
' iMax : INT
' bQuiet : INT
' pcwchUsed : INT* in/out
Declare PtrSafe Function LoadStringRCEx Lib "mscoree" ( _
ByVal lcid As Long, _
ByVal iResouceID As Long, _
ByVal szBuffer As LongPtr, _
ByVal iMax As Long, _
ByVal bQuiet As Long, _
ByRef pcwchUsed As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LoadStringRCEx = ctypes.windll.mscoree.LoadStringRCEx
LoadStringRCEx.restype = ctypes.c_int
LoadStringRCEx.argtypes = [
wintypes.DWORD, # lcid : DWORD
wintypes.DWORD, # iResouceID : DWORD
wintypes.LPWSTR, # szBuffer : LPWSTR out
ctypes.c_int, # iMax : INT
ctypes.c_int, # bQuiet : INT
ctypes.POINTER(ctypes.c_int), # pcwchUsed : INT* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('MSCorEE.dll')
LoadStringRCEx = Fiddle::Function.new(
lib['LoadStringRCEx'],
[
-Fiddle::TYPE_INT, # lcid : DWORD
-Fiddle::TYPE_INT, # iResouceID : DWORD
Fiddle::TYPE_VOIDP, # szBuffer : LPWSTR out
Fiddle::TYPE_INT, # iMax : INT
Fiddle::TYPE_INT, # bQuiet : INT
Fiddle::TYPE_VOIDP, # pcwchUsed : INT* in/out
],
Fiddle::TYPE_INT)#[link(name = "mscoree")]
extern "system" {
fn LoadStringRCEx(
lcid: u32, // DWORD
iResouceID: u32, // DWORD
szBuffer: *mut u16, // LPWSTR out
iMax: i32, // INT
bQuiet: i32, // INT
pcwchUsed: *mut i32 // INT* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("MSCorEE.dll")]
public static extern int LoadStringRCEx(uint lcid, uint iResouceID, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder szBuffer, int iMax, int bQuiet, ref int pcwchUsed);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MSCorEE_LoadStringRCEx' -Namespace Win32 -PassThru
# $api::LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed)#uselib "MSCorEE.dll"
#func global LoadStringRCEx "LoadStringRCEx" sptr, sptr, sptr, sptr, sptr, sptr
; LoadStringRCEx lcid, iResouceID, varptr(szBuffer), iMax, bQuiet, varptr(pcwchUsed) ; 戻り値は stat
; lcid : DWORD -> "sptr"
; iResouceID : DWORD -> "sptr"
; szBuffer : LPWSTR out -> "sptr"
; iMax : INT -> "sptr"
; bQuiet : INT -> "sptr"
; pcwchUsed : INT* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "MSCorEE.dll" #cfunc global LoadStringRCEx "LoadStringRCEx" int, int, var, int, int, var ; res = LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed) ; lcid : DWORD -> "int" ; iResouceID : DWORD -> "int" ; szBuffer : LPWSTR out -> "var" ; iMax : INT -> "int" ; bQuiet : INT -> "int" ; pcwchUsed : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "MSCorEE.dll" #cfunc global LoadStringRCEx "LoadStringRCEx" int, int, sptr, int, int, sptr ; res = LoadStringRCEx(lcid, iResouceID, varptr(szBuffer), iMax, bQuiet, varptr(pcwchUsed)) ; lcid : DWORD -> "int" ; iResouceID : DWORD -> "int" ; szBuffer : LPWSTR out -> "sptr" ; iMax : INT -> "int" ; bQuiet : INT -> "int" ; pcwchUsed : INT* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT LoadStringRCEx(DWORD lcid, DWORD iResouceID, LPWSTR szBuffer, INT iMax, INT bQuiet, INT* pcwchUsed) #uselib "MSCorEE.dll" #cfunc global LoadStringRCEx "LoadStringRCEx" int, int, var, int, int, var ; res = LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed) ; lcid : DWORD -> "int" ; iResouceID : DWORD -> "int" ; szBuffer : LPWSTR out -> "var" ; iMax : INT -> "int" ; bQuiet : INT -> "int" ; pcwchUsed : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT LoadStringRCEx(DWORD lcid, DWORD iResouceID, LPWSTR szBuffer, INT iMax, INT bQuiet, INT* pcwchUsed) #uselib "MSCorEE.dll" #cfunc global LoadStringRCEx "LoadStringRCEx" int, int, intptr, int, int, intptr ; res = LoadStringRCEx(lcid, iResouceID, varptr(szBuffer), iMax, bQuiet, varptr(pcwchUsed)) ; lcid : DWORD -> "int" ; iResouceID : DWORD -> "int" ; szBuffer : LPWSTR out -> "intptr" ; iMax : INT -> "int" ; bQuiet : INT -> "int" ; pcwchUsed : INT* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mscoree = windows.NewLazySystemDLL("MSCorEE.dll")
procLoadStringRCEx = mscoree.NewProc("LoadStringRCEx")
)
// lcid (DWORD), iResouceID (DWORD), szBuffer (LPWSTR out), iMax (INT), bQuiet (INT), pcwchUsed (INT* in/out)
r1, _, err := procLoadStringRCEx.Call(
uintptr(lcid),
uintptr(iResouceID),
uintptr(szBuffer),
uintptr(iMax),
uintptr(bQuiet),
uintptr(pcwchUsed),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction LoadStringRCEx(
lcid: DWORD; // DWORD
iResouceID: DWORD; // DWORD
szBuffer: PWideChar; // LPWSTR out
iMax: Integer; // INT
bQuiet: Integer; // INT
pcwchUsed: Pointer // INT* in/out
): Integer; stdcall;
external 'MSCorEE.dll' name 'LoadStringRCEx';result := DllCall("MSCorEE\LoadStringRCEx"
, "UInt", lcid ; DWORD
, "UInt", iResouceID ; DWORD
, "Ptr", szBuffer ; LPWSTR out
, "Int", iMax ; INT
, "Int", bQuiet ; INT
, "Ptr", pcwchUsed ; INT* in/out
, "Int") ; return: HRESULT●LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed) = DLL("MSCorEE.dll", "int LoadStringRCEx(dword, dword, char*, int, int, void*)")
# 呼び出し: LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed)
# lcid : DWORD -> "dword"
# iResouceID : DWORD -> "dword"
# szBuffer : LPWSTR out -> "char*"
# iMax : INT -> "int"
# bQuiet : INT -> "int"
# pcwchUsed : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mscoree" fn LoadStringRCEx(
lcid: u32, // DWORD
iResouceID: u32, // DWORD
szBuffer: [*c]u16, // LPWSTR out
iMax: i32, // INT
bQuiet: i32, // INT
pcwchUsed: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) i32;proc LoadStringRCEx(
lcid: uint32, # DWORD
iResouceID: uint32, # DWORD
szBuffer: ptr uint16, # LPWSTR out
iMax: int32, # INT
bQuiet: int32, # INT
pcwchUsed: ptr int32 # INT* in/out
): int32 {.importc: "LoadStringRCEx", stdcall, dynlib: "MSCorEE.dll".}pragma(lib, "mscoree");
extern(Windows)
int LoadStringRCEx(
uint lcid, // DWORD
uint iResouceID, // DWORD
wchar* szBuffer, // LPWSTR out
int iMax, // INT
int bQuiet, // INT
int* pcwchUsed // INT* in/out
);ccall((:LoadStringRCEx, "MSCorEE.dll"), stdcall, Int32,
(UInt32, UInt32, Ptr{UInt16}, Int32, Int32, Ptr{Int32}),
lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed)
# lcid : DWORD -> UInt32
# iResouceID : DWORD -> UInt32
# szBuffer : LPWSTR out -> Ptr{UInt16}
# iMax : INT -> Int32
# bQuiet : INT -> Int32
# pcwchUsed : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t LoadStringRCEx(
uint32_t lcid,
uint32_t iResouceID,
uint16_t* szBuffer,
int32_t iMax,
int32_t bQuiet,
int32_t* pcwchUsed);
]]
local mscoree = ffi.load("mscoree")
-- mscoree.LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed)
-- lcid : DWORD
-- iResouceID : DWORD
-- szBuffer : LPWSTR out
-- iMax : INT
-- bQuiet : INT
-- pcwchUsed : INT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('MSCorEE.dll');
const LoadStringRCEx = lib.func('__stdcall', 'LoadStringRCEx', 'int32_t', ['uint32_t', 'uint32_t', 'uint16_t *', 'int32_t', 'int32_t', 'int32_t *']);
// LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed)
// lcid : DWORD -> 'uint32_t'
// iResouceID : DWORD -> 'uint32_t'
// szBuffer : LPWSTR out -> 'uint16_t *'
// iMax : INT -> 'int32_t'
// bQuiet : INT -> 'int32_t'
// pcwchUsed : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("MSCorEE.dll", {
LoadStringRCEx: { parameters: ["u32", "u32", "buffer", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed)
// lcid : DWORD -> "u32"
// iResouceID : DWORD -> "u32"
// szBuffer : LPWSTR out -> "buffer"
// iMax : INT -> "i32"
// bQuiet : INT -> "i32"
// pcwchUsed : INT* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t LoadStringRCEx(
uint32_t lcid,
uint32_t iResouceID,
uint16_t* szBuffer,
int32_t iMax,
int32_t bQuiet,
int32_t* pcwchUsed);
C, "MSCorEE.dll");
// $ffi->LoadStringRCEx(lcid, iResouceID, szBuffer, iMax, bQuiet, pcwchUsed);
// lcid : DWORD
// iResouceID : DWORD
// szBuffer : LPWSTR out
// iMax : INT
// bQuiet : INT
// pcwchUsed : INT* in/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 Mscoree extends StdCallLibrary {
Mscoree INSTANCE = Native.load("mscoree", Mscoree.class);
int LoadStringRCEx(
int lcid, // DWORD
int iResouceID, // DWORD
char[] szBuffer, // LPWSTR out
int iMax, // INT
int bQuiet, // INT
IntByReference pcwchUsed // INT* in/out
);
}@[Link("mscoree")]
lib LibMSCorEE
fun LoadStringRCEx = LoadStringRCEx(
lcid : UInt32, # DWORD
iResouceID : UInt32, # DWORD
szBuffer : UInt16*, # LPWSTR out
iMax : Int32, # INT
bQuiet : Int32, # INT
pcwchUsed : Int32* # INT* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LoadStringRCExNative = Int32 Function(Uint32, Uint32, Pointer<Utf16>, Int32, Int32, Pointer<Int32>);
typedef LoadStringRCExDart = int Function(int, int, Pointer<Utf16>, int, int, Pointer<Int32>);
final LoadStringRCEx = DynamicLibrary.open('MSCorEE.dll')
.lookupFunction<LoadStringRCExNative, LoadStringRCExDart>('LoadStringRCEx');
// lcid : DWORD -> Uint32
// iResouceID : DWORD -> Uint32
// szBuffer : LPWSTR out -> Pointer<Utf16>
// iMax : INT -> Int32
// bQuiet : INT -> Int32
// pcwchUsed : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function LoadStringRCEx(
lcid: DWORD; // DWORD
iResouceID: DWORD; // DWORD
szBuffer: PWideChar; // LPWSTR out
iMax: Integer; // INT
bQuiet: Integer; // INT
pcwchUsed: Pointer // INT* in/out
): Integer; stdcall;
external 'MSCorEE.dll' name 'LoadStringRCEx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LoadStringRCEx"
c_LoadStringRCEx :: Word32 -> Word32 -> CWString -> Int32 -> Int32 -> Ptr Int32 -> IO Int32
-- lcid : DWORD -> Word32
-- iResouceID : DWORD -> Word32
-- szBuffer : LPWSTR out -> CWString
-- iMax : INT -> Int32
-- bQuiet : INT -> Int32
-- pcwchUsed : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let loadstringrcex =
foreign "LoadStringRCEx"
(uint32_t @-> uint32_t @-> (ptr uint16_t) @-> int32_t @-> int32_t @-> (ptr int32_t) @-> returning int32_t)
(* lcid : DWORD -> uint32_t *)
(* iResouceID : DWORD -> uint32_t *)
(* szBuffer : LPWSTR out -> (ptr uint16_t) *)
(* iMax : INT -> int32_t *)
(* bQuiet : INT -> int32_t *)
(* pcwchUsed : INT* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mscoree (t "MSCorEE.dll"))
(cffi:use-foreign-library mscoree)
(cffi:defcfun ("LoadStringRCEx" load-string-rcex :convention :stdcall) :int32
(lcid :uint32) ; DWORD
(i-resouce-id :uint32) ; DWORD
(sz-buffer :pointer) ; LPWSTR out
(i-max :int32) ; INT
(b-quiet :int32) ; INT
(pcwch-used :pointer)) ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LoadStringRCEx = Win32::API::More->new('MSCorEE',
'int LoadStringRCEx(DWORD lcid, DWORD iResouceID, LPWSTR szBuffer, int iMax, int bQuiet, LPVOID pcwchUsed)');
# my $ret = $LoadStringRCEx->Call($lcid, $iResouceID, $szBuffer, $iMax, $bQuiet, $pcwchUsed);
# lcid : DWORD -> DWORD
# iResouceID : DWORD -> DWORD
# szBuffer : LPWSTR out -> LPWSTR
# iMax : INT -> int
# bQuiet : INT -> int
# pcwchUsed : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f LoadStringRC — リソースIDから文字列リソースを読み込む。