ホーム › System.WinRT › RoTransformErrorW
RoTransformErrorW
関数既存のWinRTエラーを別のHRESULTとメッセージへ変換する。
シグネチャ
// api-ms-win-core-winrt-error-l1-1-0.dll (Unicode / -W)
#include <windows.h>
BOOL RoTransformErrorW(
HRESULT oldError,
HRESULT newError,
DWORD cchMax,
LPCWSTR message // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| oldError | HRESULT | in | 変換前の元エラーを示すHRESULTコード。 |
| newError | HRESULT | in | 変換後の新しいエラーを示すHRESULTコード。 |
| cchMax | DWORD | in | messageの最大文字数。0で全長を使用する。 |
| message | LPCWSTR | inoptional | 新エラーに付随する説明メッセージ文字列(Unicode)。 |
戻り値の型: BOOL
各言語での呼び出し定義
// api-ms-win-core-winrt-error-l1-1-0.dll (Unicode / -W)
#include <windows.h>
BOOL RoTransformErrorW(
HRESULT oldError,
HRESULT newError,
DWORD cchMax,
LPCWSTR message // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-winrt-error-l1-1-0.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool RoTransformErrorW(
int oldError, // HRESULT
int newError, // HRESULT
uint cchMax, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string message // LPCWSTR optional
);<DllImport("api-ms-win-core-winrt-error-l1-1-0.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RoTransformErrorW(
oldError As Integer, ' HRESULT
newError As Integer, ' HRESULT
cchMax As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> message As String ' LPCWSTR optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' oldError : HRESULT
' newError : HRESULT
' cchMax : DWORD
' message : LPCWSTR optional
Declare PtrSafe Function RoTransformErrorW Lib "api-ms-win-core-winrt-error-l1-1-0" ( _
ByVal oldError As Long, _
ByVal newError As Long, _
ByVal cchMax As Long, _
ByVal message As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RoTransformErrorW = ctypes.windll.LoadLibrary("api-ms-win-core-winrt-error-l1-1-0.dll").RoTransformErrorW
RoTransformErrorW.restype = wintypes.BOOL
RoTransformErrorW.argtypes = [
ctypes.c_int, # oldError : HRESULT
ctypes.c_int, # newError : HRESULT
wintypes.DWORD, # cchMax : DWORD
wintypes.LPCWSTR, # message : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-winrt-error-l1-1-0.dll')
RoTransformErrorW = Fiddle::Function.new(
lib['RoTransformErrorW'],
[
Fiddle::TYPE_INT, # oldError : HRESULT
Fiddle::TYPE_INT, # newError : HRESULT
-Fiddle::TYPE_INT, # cchMax : DWORD
Fiddle::TYPE_VOIDP, # message : LPCWSTR optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "api-ms-win-core-winrt-error-l1-1-0")]
extern "system" {
fn RoTransformErrorW(
oldError: i32, // HRESULT
newError: i32, // HRESULT
cchMax: u32, // DWORD
message: *const u16 // LPCWSTR optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-winrt-error-l1-1-0.dll", CharSet = CharSet.Unicode)]
public static extern bool RoTransformErrorW(int oldError, int newError, uint cchMax, [MarshalAs(UnmanagedType.LPWStr)] string message);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-winrt-error-l1-1-0_RoTransformErrorW' -Namespace Win32 -PassThru
# $api::RoTransformErrorW(oldError, newError, cchMax, message)#uselib "api-ms-win-core-winrt-error-l1-1-0.dll"
#func global RoTransformErrorW "RoTransformErrorW" wptr, wptr, wptr, wptr
; RoTransformErrorW oldError, newError, cchMax, message ; 戻り値は stat
; oldError : HRESULT -> "wptr"
; newError : HRESULT -> "wptr"
; cchMax : DWORD -> "wptr"
; message : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "api-ms-win-core-winrt-error-l1-1-0.dll"
#cfunc global RoTransformErrorW "RoTransformErrorW" int, int, int, wstr
; res = RoTransformErrorW(oldError, newError, cchMax, message)
; oldError : HRESULT -> "int"
; newError : HRESULT -> "int"
; cchMax : DWORD -> "int"
; message : LPCWSTR optional -> "wstr"; BOOL RoTransformErrorW(HRESULT oldError, HRESULT newError, DWORD cchMax, LPCWSTR message)
#uselib "api-ms-win-core-winrt-error-l1-1-0.dll"
#cfunc global RoTransformErrorW "RoTransformErrorW" int, int, int, wstr
; res = RoTransformErrorW(oldError, newError, cchMax, message)
; oldError : HRESULT -> "int"
; newError : HRESULT -> "int"
; cchMax : DWORD -> "int"
; message : LPCWSTR optional -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
api_ms_win_core_winrt_error_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-winrt-error-l1-1-0.dll")
procRoTransformErrorW = api_ms_win_core_winrt_error_l1_1_0.NewProc("RoTransformErrorW")
)
// oldError (HRESULT), newError (HRESULT), cchMax (DWORD), message (LPCWSTR optional)
r1, _, err := procRoTransformErrorW.Call(
uintptr(oldError),
uintptr(newError),
uintptr(cchMax),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(message))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction RoTransformErrorW(
oldError: Integer; // HRESULT
newError: Integer; // HRESULT
cchMax: DWORD; // DWORD
message: PWideChar // LPCWSTR optional
): BOOL; stdcall;
external 'api-ms-win-core-winrt-error-l1-1-0.dll' name 'RoTransformErrorW';result := DllCall("api-ms-win-core-winrt-error-l1-1-0\RoTransformErrorW"
, "Int", oldError ; HRESULT
, "Int", newError ; HRESULT
, "UInt", cchMax ; DWORD
, "WStr", message ; LPCWSTR optional
, "Int") ; return: BOOL●RoTransformErrorW(oldError, newError, cchMax, message) = DLL("api-ms-win-core-winrt-error-l1-1-0.dll", "bool RoTransformErrorW(int, int, dword, char*)")
# 呼び出し: RoTransformErrorW(oldError, newError, cchMax, message)
# oldError : HRESULT -> "int"
# newError : HRESULT -> "int"
# cchMax : DWORD -> "dword"
# message : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "api-ms-win-core-winrt-error-l1-1-0" fn RoTransformErrorW(
oldError: i32, // HRESULT
newError: i32, // HRESULT
cchMax: u32, // DWORD
message: [*c]const u16 // LPCWSTR optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RoTransformErrorW(
oldError: int32, # HRESULT
newError: int32, # HRESULT
cchMax: uint32, # DWORD
message: WideCString # LPCWSTR optional
): int32 {.importc: "RoTransformErrorW", stdcall, dynlib: "api-ms-win-core-winrt-error-l1-1-0.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "api-ms-win-core-winrt-error-l1-1-0");
extern(Windows)
int RoTransformErrorW(
int oldError, // HRESULT
int newError, // HRESULT
uint cchMax, // DWORD
const(wchar)* message // LPCWSTR optional
);ccall((:RoTransformErrorW, "api-ms-win-core-winrt-error-l1-1-0.dll"), stdcall, Int32,
(Int32, Int32, UInt32, Cwstring),
oldError, newError, cchMax, message)
# oldError : HRESULT -> Int32
# newError : HRESULT -> Int32
# cchMax : DWORD -> UInt32
# message : LPCWSTR optional -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t RoTransformErrorW(
int32_t oldError,
int32_t newError,
uint32_t cchMax,
const uint16_t* message);
]]
local api-ms-win-core-winrt-error-l1-1-0 = ffi.load("api-ms-win-core-winrt-error-l1-1-0")
-- api-ms-win-core-winrt-error-l1-1-0.RoTransformErrorW(oldError, newError, cchMax, message)
-- oldError : HRESULT
-- newError : HRESULT
-- cchMax : DWORD
-- message : LPCWSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-winrt-error-l1-1-0.dll');
const RoTransformErrorW = lib.func('__stdcall', 'RoTransformErrorW', 'int32_t', ['int32_t', 'int32_t', 'uint32_t', 'str16']);
// RoTransformErrorW(oldError, newError, cchMax, message)
// oldError : HRESULT -> 'int32_t'
// newError : HRESULT -> 'int32_t'
// cchMax : DWORD -> 'uint32_t'
// message : LPCWSTR optional -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-winrt-error-l1-1-0.dll", {
RoTransformErrorW: { parameters: ["i32", "i32", "u32", "buffer"], result: "i32" },
});
// lib.symbols.RoTransformErrorW(oldError, newError, cchMax, message)
// oldError : HRESULT -> "i32"
// newError : HRESULT -> "i32"
// cchMax : DWORD -> "u32"
// message : LPCWSTR optional -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t RoTransformErrorW(
int32_t oldError,
int32_t newError,
uint32_t cchMax,
const uint16_t* message);
C, "api-ms-win-core-winrt-error-l1-1-0.dll");
// $ffi->RoTransformErrorW(oldError, newError, cchMax, message);
// oldError : HRESULT
// newError : HRESULT
// cchMax : DWORD
// message : LPCWSTR 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 Api-ms-win-core-winrt-error-l1-1-0 extends StdCallLibrary {
Api-ms-win-core-winrt-error-l1-1-0 INSTANCE = Native.load("api-ms-win-core-winrt-error-l1-1-0", Api-ms-win-core-winrt-error-l1-1-0.class, W32APIOptions.UNICODE_OPTIONS);
boolean RoTransformErrorW(
int oldError, // HRESULT
int newError, // HRESULT
int cchMax, // DWORD
WString message // LPCWSTR optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("api-ms-win-core-winrt-error-l1-1-0")]
lib Libapi-ms-win-core-winrt-error-l1-1-0
fun RoTransformErrorW = RoTransformErrorW(
oldError : Int32, # HRESULT
newError : Int32, # HRESULT
cchMax : UInt32, # DWORD
message : UInt16* # LPCWSTR optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RoTransformErrorWNative = Int32 Function(Int32, Int32, Uint32, Pointer<Utf16>);
typedef RoTransformErrorWDart = int Function(int, int, int, Pointer<Utf16>);
final RoTransformErrorW = DynamicLibrary.open('api-ms-win-core-winrt-error-l1-1-0.dll')
.lookupFunction<RoTransformErrorWNative, RoTransformErrorWDart>('RoTransformErrorW');
// oldError : HRESULT -> Int32
// newError : HRESULT -> Int32
// cchMax : DWORD -> Uint32
// message : LPCWSTR optional -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RoTransformErrorW(
oldError: Integer; // HRESULT
newError: Integer; // HRESULT
cchMax: DWORD; // DWORD
message: PWideChar // LPCWSTR optional
): BOOL; stdcall;
external 'api-ms-win-core-winrt-error-l1-1-0.dll' name 'RoTransformErrorW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RoTransformErrorW"
c_RoTransformErrorW :: Int32 -> Int32 -> Word32 -> CWString -> IO CInt
-- oldError : HRESULT -> Int32
-- newError : HRESULT -> Int32
-- cchMax : DWORD -> Word32
-- message : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rotransformerrorw =
foreign "RoTransformErrorW"
(int32_t @-> int32_t @-> uint32_t @-> (ptr uint16_t) @-> returning int32_t)
(* oldError : HRESULT -> int32_t *)
(* newError : HRESULT -> int32_t *)
(* cchMax : DWORD -> uint32_t *)
(* message : LPCWSTR optional -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library api-ms-win-core-winrt-error-l1-1-0 (t "api-ms-win-core-winrt-error-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-winrt-error-l1-1-0)
(cffi:defcfun ("RoTransformErrorW" ro-transform-error-w :convention :stdcall) :int32
(old-error :int32) ; HRESULT
(new-error :int32) ; HRESULT
(cch-max :uint32) ; DWORD
(message (:string :encoding :utf-16le))) ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RoTransformErrorW = Win32::API::More->new('api-ms-win-core-winrt-error-l1-1-0',
'BOOL RoTransformErrorW(int oldError, int newError, DWORD cchMax, LPCWSTR message)');
# my $ret = $RoTransformErrorW->Call($oldError, $newError, $cchMax, $message);
# oldError : HRESULT -> int
# newError : HRESULT -> int
# cchMax : DWORD -> DWORD
# message : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。