ホーム › 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 | 変換元のアカウント名を指すANSI文字列。 |
| AccountNameFormat | EXTENDED_NAME_FORMAT | in | lpAccountNameの現在の形式を示すEXTENDED_NAME_FORMAT列挙値。 |
| DesiredNameFormat | EXTENDED_NAME_FORMAT | in | 変換後に得たい名前形式を示すEXTENDED_NAME_FORMAT列挙値。 |
| lpTranslatedName | LPSTR | outoptional | 変換結果の名前を受け取るANSI文字列バッファへのポインタ。 |
| nSize | DWORD* | inout | 入力時はバッファ文字数、出力時は格納文字数を示すDWORDへのポインタ。 |
戻り値の型: 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
);[return: MarshalAs(UnmanagedType.U1)]
[DllImport("SECUR32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool 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 <MarshalAs(UnmanagedType.U1)> Boolean
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 = wintypes.BOOLEAN
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 = @"
[return: MarshalAs(UnmanagedType.U1)]
[DllImport("SECUR32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool 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)。const std = @import("std");
extern "secur32" fn TranslateNameA(
lpAccountName: [*c]const u8, // LPCSTR
AccountNameFormat: i32, // EXTENDED_NAME_FORMAT
DesiredNameFormat: i32, // EXTENDED_NAME_FORMAT
lpTranslatedName: [*c]u8, // LPSTR optional, out
nSize: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) u8;proc TranslateNameA(
lpAccountName: cstring, # LPCSTR
AccountNameFormat: int32, # EXTENDED_NAME_FORMAT
DesiredNameFormat: int32, # EXTENDED_NAME_FORMAT
lpTranslatedName: ptr char, # LPSTR optional, out
nSize: ptr uint32 # DWORD* in/out
): uint8 {.importc: "TranslateNameA", stdcall, dynlib: "SECUR32.dll".}pragma(lib, "secur32");
extern(Windows)
ubyte TranslateNameA(
const(char)* lpAccountName, // LPCSTR
int AccountNameFormat, // EXTENDED_NAME_FORMAT
int DesiredNameFormat, // EXTENDED_NAME_FORMAT
char* lpTranslatedName, // LPSTR optional, out
uint* nSize // DWORD* in/out
);ccall((:TranslateNameA, "SECUR32.dll"), stdcall, UInt8,
(Cstring, Int32, Int32, Ptr{UInt8}, Ptr{UInt32}),
lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize)
# lpAccountName : LPCSTR -> Cstring
# AccountNameFormat : EXTENDED_NAME_FORMAT -> Int32
# DesiredNameFormat : EXTENDED_NAME_FORMAT -> Int32
# lpTranslatedName : LPSTR optional, out -> Ptr{UInt8}
# nSize : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint8_t TranslateNameA(
const char* lpAccountName,
int32_t AccountNameFormat,
int32_t DesiredNameFormat,
char* lpTranslatedName,
uint32_t* nSize);
]]
local secur32 = ffi.load("secur32")
-- secur32.TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize)
-- lpAccountName : LPCSTR
-- AccountNameFormat : EXTENDED_NAME_FORMAT
-- DesiredNameFormat : EXTENDED_NAME_FORMAT
-- lpTranslatedName : LPSTR optional, out
-- nSize : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const TranslateNameA = lib.func('__stdcall', 'TranslateNameA', 'uint8_t', ['str', 'int32_t', 'int32_t', 'char *', 'uint32_t *']);
// TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize)
// lpAccountName : LPCSTR -> 'str'
// AccountNameFormat : EXTENDED_NAME_FORMAT -> 'int32_t'
// DesiredNameFormat : EXTENDED_NAME_FORMAT -> 'int32_t'
// lpTranslatedName : LPSTR optional, out -> 'char *'
// nSize : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SECUR32.dll", {
TranslateNameA: { parameters: ["buffer", "i32", "i32", "buffer", "pointer"], result: "u8" },
});
// lib.symbols.TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize)
// lpAccountName : LPCSTR -> "buffer"
// AccountNameFormat : EXTENDED_NAME_FORMAT -> "i32"
// DesiredNameFormat : EXTENDED_NAME_FORMAT -> "i32"
// lpTranslatedName : LPSTR optional, out -> "buffer"
// nSize : DWORD* in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint8_t TranslateNameA(
const char* lpAccountName,
int32_t AccountNameFormat,
int32_t DesiredNameFormat,
char* lpTranslatedName,
uint32_t* nSize);
C, "SECUR32.dll");
// $ffi->TranslateNameA(lpAccountName, AccountNameFormat, DesiredNameFormat, lpTranslatedName, nSize);
// lpAccountName : LPCSTR
// AccountNameFormat : EXTENDED_NAME_FORMAT
// DesiredNameFormat : EXTENDED_NAME_FORMAT
// lpTranslatedName : LPSTR optional, out
// nSize : DWORD* in/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 Secur32 extends StdCallLibrary {
Secur32 INSTANCE = Native.load("secur32", Secur32.class, W32APIOptions.ASCII_OPTIONS);
byte TranslateNameA(
String lpAccountName, // LPCSTR
int AccountNameFormat, // EXTENDED_NAME_FORMAT
int DesiredNameFormat, // EXTENDED_NAME_FORMAT
byte[] lpTranslatedName, // LPSTR optional, out
IntByReference nSize // DWORD* in/out
);
}@[Link("secur32")]
lib LibSECUR32
fun TranslateNameA = TranslateNameA(
lpAccountName : UInt8*, # LPCSTR
AccountNameFormat : Int32, # EXTENDED_NAME_FORMAT
DesiredNameFormat : Int32, # EXTENDED_NAME_FORMAT
lpTranslatedName : UInt8*, # LPSTR optional, out
nSize : UInt32* # DWORD* in/out
) : UInt8
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef TranslateNameANative = Uint8 Function(Pointer<Utf8>, Int32, Int32, Pointer<Utf8>, Pointer<Uint32>);
typedef TranslateNameADart = int Function(Pointer<Utf8>, int, int, Pointer<Utf8>, Pointer<Uint32>);
final TranslateNameA = DynamicLibrary.open('SECUR32.dll')
.lookupFunction<TranslateNameANative, TranslateNameADart>('TranslateNameA');
// lpAccountName : LPCSTR -> Pointer<Utf8>
// AccountNameFormat : EXTENDED_NAME_FORMAT -> Int32
// DesiredNameFormat : EXTENDED_NAME_FORMAT -> Int32
// lpTranslatedName : LPSTR optional, out -> Pointer<Utf8>
// nSize : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "TranslateNameA"
c_TranslateNameA :: CString -> Int32 -> Int32 -> CString -> Ptr Word32 -> IO Word8
-- lpAccountName : LPCSTR -> CString
-- AccountNameFormat : EXTENDED_NAME_FORMAT -> Int32
-- DesiredNameFormat : EXTENDED_NAME_FORMAT -> Int32
-- lpTranslatedName : LPSTR optional, out -> CString
-- nSize : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let translatenamea =
foreign "TranslateNameA"
(string @-> int32_t @-> int32_t @-> string @-> (ptr uint32_t) @-> returning uint8_t)
(* lpAccountName : LPCSTR -> string *)
(* AccountNameFormat : EXTENDED_NAME_FORMAT -> int32_t *)
(* DesiredNameFormat : EXTENDED_NAME_FORMAT -> int32_t *)
(* lpTranslatedName : LPSTR optional, out -> string *)
(* nSize : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)
(cffi:defcfun ("TranslateNameA" translate-name-a :convention :stdcall) :uint8
(lp-account-name :string) ; LPCSTR
(account-name-format :int32) ; EXTENDED_NAME_FORMAT
(desired-name-format :int32) ; EXTENDED_NAME_FORMAT
(lp-translated-name :pointer) ; LPSTR optional, out
(n-size :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $TranslateNameA = Win32::API::More->new('SECUR32',
'BYTE TranslateNameA(LPCSTR lpAccountName, int AccountNameFormat, int DesiredNameFormat, LPSTR lpTranslatedName, LPVOID nSize)');
# my $ret = $TranslateNameA->Call($lpAccountName, $AccountNameFormat, $DesiredNameFormat, $lpTranslatedName, $nSize);
# lpAccountName : LPCSTR -> LPCSTR
# AccountNameFormat : EXTENDED_NAME_FORMAT -> int
# DesiredNameFormat : EXTENDED_NAME_FORMAT -> int
# lpTranslatedName : LPSTR optional, out -> LPSTR
# nSize : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f TranslateNameW (Unicode版) — ディレクトリアカウント名を別の名前形式に変換する(Unicode版)。