ホーム › System.Rpc › UuidToStringW
UuidToStringW
関数UUIDをUnicode文字列形式に変換する。
シグネチャ
// RPCRT4.dll (Unicode / -W)
#include <windows.h>
RPC_STATUS UuidToStringW(
const GUID* Uuid,
LPWSTR* StringUuid
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Uuid | GUID* | in | バイナリ形式の UUID へのポインター。 |
| StringUuid | LPWSTR* | out | Uuid パラメーターで指定された UUID が格納される、null で終わる文字列へのポインター。 |
戻り値の型: RPC_STATUS
公式ドキュメント
UuidToStringW (Unicode) 関数 (rpcdce.h) は、UUID を文字列に変換します。
戻り値
解説(Remarks)
アプリケーションは UuidToString を呼び出して、バイナリ形式の UUID を文字列形式の UUID に変換します。RPC ランタイムライブラリは、StringUuid パラメーターで返される文字列用のメモリを割り当てます。そのメモリを解放するために RpcStringFree を呼び出す責任は、アプリケーションにあります。
メモ
rpcdce.h ヘッダーは、UNICODE プリプロセッサ定数の定義に応じてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして UuidToString を定義しています。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因となる場合があります。詳細については、Conventions for Function Prototypes を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// RPCRT4.dll (Unicode / -W)
#include <windows.h>
RPC_STATUS UuidToStringW(
const GUID* Uuid,
LPWSTR* StringUuid
);[DllImport("RPCRT4.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int UuidToStringW(
ref Guid Uuid, // GUID*
IntPtr StringUuid // LPWSTR* out
);<DllImport("RPCRT4.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function UuidToStringW(
ByRef Uuid As Guid, ' GUID*
StringUuid As IntPtr ' LPWSTR* out
) As Integer
End Function' Uuid : GUID*
' StringUuid : LPWSTR* out
Declare PtrSafe Function UuidToStringW Lib "rpcrt4" ( _
ByVal Uuid As LongPtr, _
ByVal StringUuid 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
UuidToStringW = ctypes.windll.rpcrt4.UuidToStringW
UuidToStringW.restype = ctypes.c_int
UuidToStringW.argtypes = [
ctypes.c_void_p, # Uuid : GUID*
ctypes.c_void_p, # StringUuid : LPWSTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('RPCRT4.dll')
UuidToStringW = Fiddle::Function.new(
lib['UuidToStringW'],
[
Fiddle::TYPE_VOIDP, # Uuid : GUID*
Fiddle::TYPE_VOIDP, # StringUuid : LPWSTR* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "rpcrt4")]
extern "system" {
fn UuidToStringW(
Uuid: *const GUID, // GUID*
StringUuid: *mut *mut u16 // LPWSTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("RPCRT4.dll", CharSet = CharSet.Unicode)]
public static extern int UuidToStringW(ref Guid Uuid, IntPtr StringUuid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RPCRT4_UuidToStringW' -Namespace Win32 -PassThru
# $api::UuidToStringW(Uuid, StringUuid)#uselib "RPCRT4.dll"
#func global UuidToStringW "UuidToStringW" wptr, wptr
; UuidToStringW varptr(Uuid), varptr(StringUuid) ; 戻り値は stat
; Uuid : GUID* -> "wptr"
; StringUuid : LPWSTR* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "RPCRT4.dll" #cfunc global UuidToStringW "UuidToStringW" var, var ; res = UuidToStringW(Uuid, StringUuid) ; Uuid : GUID* -> "var" ; StringUuid : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "RPCRT4.dll" #cfunc global UuidToStringW "UuidToStringW" sptr, sptr ; res = UuidToStringW(varptr(Uuid), varptr(StringUuid)) ; Uuid : GUID* -> "sptr" ; StringUuid : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; RPC_STATUS UuidToStringW(GUID* Uuid, LPWSTR* StringUuid) #uselib "RPCRT4.dll" #cfunc global UuidToStringW "UuidToStringW" var, var ; res = UuidToStringW(Uuid, StringUuid) ; Uuid : GUID* -> "var" ; StringUuid : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; RPC_STATUS UuidToStringW(GUID* Uuid, LPWSTR* StringUuid) #uselib "RPCRT4.dll" #cfunc global UuidToStringW "UuidToStringW" intptr, intptr ; res = UuidToStringW(varptr(Uuid), varptr(StringUuid)) ; Uuid : GUID* -> "intptr" ; StringUuid : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
rpcrt4 = windows.NewLazySystemDLL("RPCRT4.dll")
procUuidToStringW = rpcrt4.NewProc("UuidToStringW")
)
// Uuid (GUID*), StringUuid (LPWSTR* out)
r1, _, err := procUuidToStringW.Call(
uintptr(Uuid),
uintptr(StringUuid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // RPC_STATUSfunction UuidToStringW(
Uuid: PGUID; // GUID*
StringUuid: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'RPCRT4.dll' name 'UuidToStringW';result := DllCall("RPCRT4\UuidToStringW"
, "Ptr", Uuid ; GUID*
, "Ptr", StringUuid ; LPWSTR* out
, "Int") ; return: RPC_STATUS●UuidToStringW(Uuid, StringUuid) = DLL("RPCRT4.dll", "int UuidToStringW(void*, void*)")
# 呼び出し: UuidToStringW(Uuid, StringUuid)
# Uuid : GUID* -> "void*"
# StringUuid : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "rpcrt4" fn UuidToStringW(
Uuid: [*c]GUID, // GUID*
StringUuid: [*c][*c]u16 // LPWSTR* out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc UuidToStringW(
Uuid: ptr GUID, # GUID*
StringUuid: ptr WideCString # LPWSTR* out
): int32 {.importc: "UuidToStringW", stdcall, dynlib: "RPCRT4.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "rpcrt4");
extern(Windows)
int UuidToStringW(
GUID* Uuid, // GUID*
wchar** StringUuid // LPWSTR* out
);ccall((:UuidToStringW, "RPCRT4.dll"), stdcall, Int32,
(Ptr{GUID}, Ptr{Ptr{UInt16}}),
Uuid, StringUuid)
# Uuid : GUID* -> Ptr{GUID}
# StringUuid : LPWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t UuidToStringW(
void* Uuid,
uint16_t** StringUuid);
]]
local rpcrt4 = ffi.load("rpcrt4")
-- rpcrt4.UuidToStringW(Uuid, StringUuid)
-- Uuid : GUID*
-- StringUuid : LPWSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('RPCRT4.dll');
const UuidToStringW = lib.func('__stdcall', 'UuidToStringW', 'int32_t', ['void *', 'void *']);
// UuidToStringW(Uuid, StringUuid)
// Uuid : GUID* -> 'void *'
// StringUuid : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RPCRT4.dll", {
UuidToStringW: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.UuidToStringW(Uuid, StringUuid)
// Uuid : GUID* -> "pointer"
// StringUuid : LPWSTR* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t UuidToStringW(
void* Uuid,
uint16_t** StringUuid);
C, "RPCRT4.dll");
// $ffi->UuidToStringW(Uuid, StringUuid);
// Uuid : GUID*
// StringUuid : LPWSTR* 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 Rpcrt4 extends StdCallLibrary {
Rpcrt4 INSTANCE = Native.load("rpcrt4", Rpcrt4.class, W32APIOptions.UNICODE_OPTIONS);
int UuidToStringW(
Pointer Uuid, // GUID*
PointerByReference StringUuid // LPWSTR* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("rpcrt4")]
lib LibRPCRT4
fun UuidToStringW = UuidToStringW(
Uuid : GUID*, # GUID*
StringUuid : UInt16** # LPWSTR* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef UuidToStringWNative = Int32 Function(Pointer<Void>, Pointer<Pointer<Utf16>>);
typedef UuidToStringWDart = int Function(Pointer<Void>, Pointer<Pointer<Utf16>>);
final UuidToStringW = DynamicLibrary.open('RPCRT4.dll')
.lookupFunction<UuidToStringWNative, UuidToStringWDart>('UuidToStringW');
// Uuid : GUID* -> Pointer<Void>
// StringUuid : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function UuidToStringW(
Uuid: PGUID; // GUID*
StringUuid: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'RPCRT4.dll' name 'UuidToStringW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "UuidToStringW"
c_UuidToStringW :: Ptr () -> Ptr CWString -> IO Int32
-- Uuid : GUID* -> Ptr ()
-- StringUuid : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let uuidtostringw =
foreign "UuidToStringW"
((ptr void) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* Uuid : GUID* -> (ptr void) *)
(* StringUuid : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library rpcrt4 (t "RPCRT4.dll"))
(cffi:use-foreign-library rpcrt4)
(cffi:defcfun ("UuidToStringW" uuid-to-string-w :convention :stdcall) :int32
(uuid :pointer) ; GUID*
(string-uuid :pointer)) ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $UuidToStringW = Win32::API::More->new('RPCRT4',
'int UuidToStringW(LPVOID Uuid, LPVOID StringUuid)');
# my $ret = $UuidToStringW->Call($Uuid, $StringUuid);
# Uuid : GUID* -> LPVOID
# StringUuid : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f UuidToStringA (ANSI版) — UUIDをANSI文字列形式に変換する。
使用する型