Win32 API 日本語リファレンス
ホームSystem.WinRT › RoTransformErrorW

RoTransformErrorW

関数
既存のWinRTエラーを別のHRESULTとメッセージへ変換する。
DLLapi-ms-win-core-winrt-error-l1-1-0.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

// 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
);

パラメーター

名前方向
oldErrorHRESULTin
newErrorHRESULTin
cchMaxDWORDin
messageLPCWSTRinoptional

戻り値の型: 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 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   // BOOL
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';
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 版の利用を推奨。