ホーム › Security.Authentication.Identity › TranslateNameA
TranslateNameA
関数ディレクトリアカウント名を別の名前形式に変換する(ANSI版)。
シグネチャ
// SECUR32.dll (ANSI / -A)
#include <windows.h>
BOOLEAN TranslateNameA(
LPCSTR lpAccountName,
EXTENDED_NAME_FORMAT AccountNameFormat,
EXTENDED_NAME_FORMAT DesiredNameFormat,
LPSTR lpTranslatedName, // optional
DWORD* nSize
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpAccountName | LPCSTR | in |
| AccountNameFormat | EXTENDED_NAME_FORMAT | in |
| DesiredNameFormat | EXTENDED_NAME_FORMAT | in |
| lpTranslatedName | LPSTR | outoptional |
| nSize | DWORD* | inout |
戻り値の型: BOOLEAN
各言語での呼び出し定義
// SECUR32.dll (ANSI / -A)
#include <windows.h>
BOOLEAN TranslateNameA(
LPCSTR lpAccountName,
EXTENDED_NAME_FORMAT AccountNameFormat,
EXTENDED_NAME_FORMAT DesiredNameFormat,
LPSTR lpTranslatedName, // optional
DWORD* nSize
);[DllImport("SECUR32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern byte TranslateNameA(
[MarshalAs(UnmanagedType.LPStr)] string lpAccountName, // LPCSTR
int AccountNameFormat, // EXTENDED_NAME_FORMAT
int DesiredNameFormat, // EXTENDED_NAME_FORMAT
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpTranslatedName, // LPSTR optional, out
ref uint nSize // DWORD* in/out
);<DllImport("SECUR32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function TranslateNameA(
<MarshalAs(UnmanagedType.LPStr)> lpAccountName As String, ' LPCSTR
AccountNameFormat As Integer, ' EXTENDED_NAME_FORMAT
DesiredNameFormat As Integer, ' EXTENDED_NAME_FORMAT
<MarshalAs(UnmanagedType.LPStr)> lpTranslatedName As System.Text.StringBuilder, ' LPSTR optional, out
ByRef nSize As UInteger ' DWORD* in/out
) As Byte
End Function' lpAccountName : LPCSTR
' AccountNameFormat : EXTENDED_NAME_FORMAT
' DesiredNameFormat : EXTENDED_NAME_FORMAT
' lpTranslatedName : LPSTR optional, out
' nSize : DWORD* in/out
Declare PtrSafe Function TranslateNameA Lib "secur32" ( _
ByVal lpAccountName As String, _
ByVal AccountNameFormat As Long, _
ByVal DesiredNameFormat As Long, _
ByVal lpTranslatedName As String, _
ByRef nSize As Long) As Byte
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
TranslateNameA = ctypes.windll.secur32.TranslateNameA
TranslateNameA.restype = ctypes.c_byte
TranslateNameA.argtypes = [
wintypes.LPCSTR, # lpAccountName : LPCSTR
ctypes.c_int, # AccountNameFormat : EXTENDED_NAME_FORMAT
ctypes.c_int, # DesiredNameFormat : EXTENDED_NAME_FORMAT
wintypes.LPSTR, # lpTranslatedName : LPSTR optional, out
ctypes.POINTER(wintypes.DWORD), # nSize : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SECUR32.dll')
TranslateNameA = Fiddle::Function.new(
lib['TranslateNameA'],
[
Fiddle::TYPE_VOIDP, # lpAccountName : LPCSTR
Fiddle::TYPE_INT, # AccountNameFormat : EXTENDED_NAME_FORMAT
Fiddle::TYPE_INT, # DesiredNameFormat : EXTENDED_NAME_FORMAT
Fiddle::TYPE_VOIDP, # lpTranslatedName : LPSTR optional, out
Fiddle::TYPE_VOIDP, # nSize : DWORD* in/out
],
Fiddle::TYPE_CHAR)#[link(name = "secur32")]
extern "system" {
fn TranslateNameA(
lpAccountName: *const u8, // LPCSTR
AccountNameFormat: i32, // EXTENDED_NAME_FORMAT
DesiredNameFormat: i32, // EXTENDED_NAME_FORMAT
lpTranslatedName: *mut u8, // LPSTR optional, out
nSize: *mut u32 // DWORD* in/out
) -> u8;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SECUR32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern byte TranslateNameA([MarshalAs(UnmanagedType.LPStr)] string lpAccountName, int AccountNameFormat, int DesiredNameFormat, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder lpTranslatedName, ref uint nSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_TranslateNameA' -Namespace Win32 -PassThru
# $api::TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize)#uselib "SECUR32.dll"
#func global TranslateNameA "TranslateNameA" sptr, sptr, sptr, sptr, sptr
; TranslateNameA lpAccountName, AccountNameFormat, DesiredNameFormat, varptr(lpTranslatedName), varptr(nSize) ; 戻り値は stat
; lpAccountName : LPCSTR -> "sptr"
; AccountNameFormat : EXTENDED_NAME_FORMAT -> "sptr"
; DesiredNameFormat : EXTENDED_NAME_FORMAT -> "sptr"
; lpTranslatedName : LPSTR optional, out -> "sptr"
; nSize : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SECUR32.dll" #cfunc global TranslateNameA "TranslateNameA" str, int, int, var, var ; res = TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize) ; lpAccountName : LPCSTR -> "str" ; AccountNameFormat : EXTENDED_NAME_FORMAT -> "int" ; DesiredNameFormat : EXTENDED_NAME_FORMAT -> "int" ; lpTranslatedName : LPSTR optional, out -> "var" ; nSize : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SECUR32.dll" #cfunc global TranslateNameA "TranslateNameA" str, int, int, sptr, sptr ; res = TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, varptr(lpTranslatedName), varptr(nSize)) ; lpAccountName : LPCSTR -> "str" ; AccountNameFormat : EXTENDED_NAME_FORMAT -> "int" ; DesiredNameFormat : EXTENDED_NAME_FORMAT -> "int" ; lpTranslatedName : LPSTR optional, out -> "sptr" ; nSize : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOLEAN TranslateNameA(LPCSTR lpAccountName, EXTENDED_NAME_FORMAT AccountNameFormat, EXTENDED_NAME_FORMAT DesiredNameFormat, LPSTR lpTranslatedName, DWORD* nSize) #uselib "SECUR32.dll" #cfunc global TranslateNameA "TranslateNameA" str, int, int, var, var ; res = TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize) ; lpAccountName : LPCSTR -> "str" ; AccountNameFormat : EXTENDED_NAME_FORMAT -> "int" ; DesiredNameFormat : EXTENDED_NAME_FORMAT -> "int" ; lpTranslatedName : LPSTR optional, out -> "var" ; nSize : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOLEAN TranslateNameA(LPCSTR lpAccountName, EXTENDED_NAME_FORMAT AccountNameFormat, EXTENDED_NAME_FORMAT DesiredNameFormat, LPSTR lpTranslatedName, DWORD* nSize) #uselib "SECUR32.dll" #cfunc global TranslateNameA "TranslateNameA" str, int, int, intptr, intptr ; res = TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, varptr(lpTranslatedName), varptr(nSize)) ; lpAccountName : LPCSTR -> "str" ; AccountNameFormat : EXTENDED_NAME_FORMAT -> "int" ; DesiredNameFormat : EXTENDED_NAME_FORMAT -> "int" ; lpTranslatedName : LPSTR optional, out -> "intptr" ; nSize : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
secur32 = windows.NewLazySystemDLL("SECUR32.dll")
procTranslateNameA = secur32.NewProc("TranslateNameA")
)
// lpAccountName (LPCSTR), AccountNameFormat (EXTENDED_NAME_FORMAT), DesiredNameFormat (EXTENDED_NAME_FORMAT), lpTranslatedName (LPSTR optional, out), nSize (DWORD* in/out)
r1, _, err := procTranslateNameA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpAccountName))),
uintptr(AccountNameFormat),
uintptr(DesiredNameFormat),
uintptr(lpTranslatedName),
uintptr(nSize),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLEANfunction TranslateNameA(
lpAccountName: PAnsiChar; // LPCSTR
AccountNameFormat: Integer; // EXTENDED_NAME_FORMAT
DesiredNameFormat: Integer; // EXTENDED_NAME_FORMAT
lpTranslatedName: PAnsiChar; // LPSTR optional, out
nSize: Pointer // DWORD* in/out
): ByteBool; stdcall;
external 'SECUR32.dll' name 'TranslateNameA';result := DllCall("SECUR32\TranslateNameA"
, "AStr", lpAccountName ; LPCSTR
, "Int", AccountNameFormat ; EXTENDED_NAME_FORMAT
, "Int", DesiredNameFormat ; EXTENDED_NAME_FORMAT
, "Ptr", lpTranslatedName ; LPSTR optional, out
, "Ptr", nSize ; DWORD* in/out
, "Char") ; return: BOOLEAN●TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize) = DLL("SECUR32.dll", "byte TranslateNameA(char*, int, int, char*, void*)")
# 呼び出し: TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize)
# lpAccountName : LPCSTR -> "char*"
# AccountNameFormat : EXTENDED_NAME_FORMAT -> "int"
# DesiredNameFormat : EXTENDED_NAME_FORMAT -> "int"
# lpTranslatedName : LPSTR optional, out -> "char*"
# nSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。