ホーム › Security.Authorization › ConvertSidToStringSidW
ConvertSidToStringSidW
関数SIDを文字列形式のSIDに変換する。
シグネチャ
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL ConvertSidToStringSidW(
PSID Sid,
LPWSTR* StringSid
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Sid | PSID | in | 変換する SID 構造体へのポインターです。 |
| StringSid | LPWSTR* | out | null で終わる SID 文字列へのポインターを受け取る変数へのポインターです。返されたバッファーを解放するには、 LocalFree 関数を呼び出します。 |
戻り値の型: BOOL
公式ドキュメント
セキュリティ識別子 (SID) を、表示、保存、または送信に適した文字列形式に変換します。(Unicode)
戻り値
関数が成功した場合、戻り値は 0 以外になります。
関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。GetLastError 関数は、次のいずれかのエラーコードを返すことがあります。
| 戻り値 | 説明 |
|---|---|
| メモリが不足しています。 | |
| SID が無効です。 | |
| いずれかのパラメーターに無効な値が含まれています。これは多くの場合、無効なポインターです。 |
解説(Remarks)
ConvertSidToStringSid 関数は、SID 文字列に標準の S-R-I-S-S… 形式を使用します。SID 文字列の表記の詳細については、 SID Components を参照してください。
メモ
sddl.h ヘッダーは ConvertSidToStringSid をエイリアスとして定義しており、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在して使用すると、不一致が生じてコンパイルエラーまたは実行時エラーを引き起こす可能性があります。詳細については、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)
各言語での呼び出し定義
// ADVAPI32.dll (Unicode / -W)
#include <windows.h>
BOOL ConvertSidToStringSidW(
PSID Sid,
LPWSTR* StringSid
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool ConvertSidToStringSidW(
IntPtr Sid, // PSID
IntPtr StringSid // LPWSTR* out
);<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function ConvertSidToStringSidW(
Sid As IntPtr, ' PSID
StringSid As IntPtr ' LPWSTR* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' Sid : PSID
' StringSid : LPWSTR* out
Declare PtrSafe Function ConvertSidToStringSidW Lib "advapi32" ( _
ByVal Sid As LongPtr, _
ByVal StringSid 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
ConvertSidToStringSidW = ctypes.windll.advapi32.ConvertSidToStringSidW
ConvertSidToStringSidW.restype = wintypes.BOOL
ConvertSidToStringSidW.argtypes = [
wintypes.HANDLE, # Sid : PSID
ctypes.c_void_p, # StringSid : LPWSTR* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
ConvertSidToStringSidW = Fiddle::Function.new(
lib['ConvertSidToStringSidW'],
[
Fiddle::TYPE_VOIDP, # Sid : PSID
Fiddle::TYPE_VOIDP, # StringSid : LPWSTR* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "advapi32")]
extern "system" {
fn ConvertSidToStringSidW(
Sid: *mut core::ffi::c_void, // PSID
StringSid: *mut *mut u16 // LPWSTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool ConvertSidToStringSidW(IntPtr Sid, IntPtr StringSid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_ConvertSidToStringSidW' -Namespace Win32 -PassThru
# $api::ConvertSidToStringSidW(Sid, StringSid)#uselib "ADVAPI32.dll"
#func global ConvertSidToStringSidW "ConvertSidToStringSidW" wptr, wptr
; ConvertSidToStringSidW Sid, varptr(StringSid) ; 戻り値は stat
; Sid : PSID -> "wptr"
; StringSid : LPWSTR* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "ADVAPI32.dll" #cfunc global ConvertSidToStringSidW "ConvertSidToStringSidW" sptr, var ; res = ConvertSidToStringSidW(Sid, StringSid) ; Sid : PSID -> "sptr" ; StringSid : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global ConvertSidToStringSidW "ConvertSidToStringSidW" sptr, sptr ; res = ConvertSidToStringSidW(Sid, varptr(StringSid)) ; Sid : PSID -> "sptr" ; StringSid : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL ConvertSidToStringSidW(PSID Sid, LPWSTR* StringSid) #uselib "ADVAPI32.dll" #cfunc global ConvertSidToStringSidW "ConvertSidToStringSidW" intptr, var ; res = ConvertSidToStringSidW(Sid, StringSid) ; Sid : PSID -> "intptr" ; StringSid : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL ConvertSidToStringSidW(PSID Sid, LPWSTR* StringSid) #uselib "ADVAPI32.dll" #cfunc global ConvertSidToStringSidW "ConvertSidToStringSidW" intptr, intptr ; res = ConvertSidToStringSidW(Sid, varptr(StringSid)) ; Sid : PSID -> "intptr" ; StringSid : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procConvertSidToStringSidW = advapi32.NewProc("ConvertSidToStringSidW")
)
// Sid (PSID), StringSid (LPWSTR* out)
r1, _, err := procConvertSidToStringSidW.Call(
uintptr(Sid),
uintptr(StringSid),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ConvertSidToStringSidW(
Sid: THandle; // PSID
StringSid: PPWideChar // LPWSTR* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'ConvertSidToStringSidW';result := DllCall("ADVAPI32\ConvertSidToStringSidW"
, "Ptr", Sid ; PSID
, "Ptr", StringSid ; LPWSTR* out
, "Int") ; return: BOOL●ConvertSidToStringSidW(Sid, StringSid) = DLL("ADVAPI32.dll", "bool ConvertSidToStringSidW(void*, void*)")
# 呼び出し: ConvertSidToStringSidW(Sid, StringSid)
# Sid : PSID -> "void*"
# StringSid : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "advapi32" fn ConvertSidToStringSidW(
Sid: ?*anyopaque, // PSID
StringSid: [*c][*c]u16 // LPWSTR* out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc ConvertSidToStringSidW(
Sid: pointer, # PSID
StringSid: ptr WideCString # LPWSTR* out
): int32 {.importc: "ConvertSidToStringSidW", stdcall, dynlib: "ADVAPI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "advapi32");
extern(Windows)
int ConvertSidToStringSidW(
void* Sid, // PSID
wchar** StringSid // LPWSTR* out
);ccall((:ConvertSidToStringSidW, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Ptr{UInt16}}),
Sid, StringSid)
# Sid : PSID -> Ptr{Cvoid}
# StringSid : LPWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t ConvertSidToStringSidW(
void* Sid,
uint16_t** StringSid);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.ConvertSidToStringSidW(Sid, StringSid)
-- Sid : PSID
-- StringSid : 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('ADVAPI32.dll');
const ConvertSidToStringSidW = lib.func('__stdcall', 'ConvertSidToStringSidW', 'int32_t', ['void *', 'void *']);
// ConvertSidToStringSidW(Sid, StringSid)
// Sid : PSID -> 'void *'
// StringSid : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
ConvertSidToStringSidW: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.ConvertSidToStringSidW(Sid, StringSid)
// Sid : PSID -> "pointer"
// StringSid : LPWSTR* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ConvertSidToStringSidW(
void* Sid,
uint16_t** StringSid);
C, "ADVAPI32.dll");
// $ffi->ConvertSidToStringSidW(Sid, StringSid);
// Sid : PSID
// StringSid : 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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
boolean ConvertSidToStringSidW(
Pointer Sid, // PSID
PointerByReference StringSid // LPWSTR* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("advapi32")]
lib LibADVAPI32
fun ConvertSidToStringSidW = ConvertSidToStringSidW(
Sid : Void*, # PSID
StringSid : 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 ConvertSidToStringSidWNative = Int32 Function(Pointer<Void>, Pointer<Pointer<Utf16>>);
typedef ConvertSidToStringSidWDart = int Function(Pointer<Void>, Pointer<Pointer<Utf16>>);
final ConvertSidToStringSidW = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<ConvertSidToStringSidWNative, ConvertSidToStringSidWDart>('ConvertSidToStringSidW');
// Sid : PSID -> Pointer<Void>
// StringSid : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ConvertSidToStringSidW(
Sid: THandle; // PSID
StringSid: PPWideChar // LPWSTR* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'ConvertSidToStringSidW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ConvertSidToStringSidW"
c_ConvertSidToStringSidW :: Ptr () -> Ptr CWString -> IO CInt
-- Sid : PSID -> Ptr ()
-- StringSid : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let convertsidtostringsidw =
foreign "ConvertSidToStringSidW"
((ptr void) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* Sid : PSID -> (ptr void) *)
(* StringSid : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("ConvertSidToStringSidW" convert-sid-to-string-sid-w :convention :stdcall) :int32
(sid :pointer) ; PSID
(string-sid :pointer)) ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ConvertSidToStringSidW = Win32::API::More->new('ADVAPI32',
'BOOL ConvertSidToStringSidW(HANDLE Sid, LPVOID StringSid)');
# my $ret = $ConvertSidToStringSidW->Call($Sid, $StringSid);
# Sid : PSID -> HANDLE
# StringSid : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f ConvertSidToStringSidA (ANSI版) — SIDを文字列形式のSIDに変換する。
公式の関連項目
- f ConvertSecurityDescriptorToStringSecurityDescriptorW — セキュリティ記述子をSDDL文字列に変換する。
- f ConvertStringSecurityDescriptorToSecurityDescriptorW — SDDL文字列をセキュリティ記述子に変換する。
- f ConvertStringSidToSidW — 文字列形式のSIDをバイナリのSIDに変換する。
- s SID