ホーム › Networking.Ldap › ldap_ufn2dnW
ldap_ufn2dnW
関数利用者向け表記の名前をDN形式に変換する(Unicode版)。
シグネチャ
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_ufn2dnW(
LPCWSTR ufn,
LPWSTR* pDn
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ufn | LPCWSTR | in | 変換元のユーザフレンドリ名文字列(Unicode)。正規のDN形式へ変換する入力。 |
| pDn | LPWSTR* | out | 変換結果のDN文字列を受け取る出力ポインタ。ldap_memfreeで解放する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_ufn2dnW(
LPCWSTR ufn,
LPWSTR* pDn
);[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_ufn2dnW(
[MarshalAs(UnmanagedType.LPWStr)] string ufn, // LPCWSTR
IntPtr pDn // LPWSTR* out
);<DllImport("WLDAP32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_ufn2dnW(
<MarshalAs(UnmanagedType.LPWStr)> ufn As String, ' LPCWSTR
pDn As IntPtr ' LPWSTR* out
) As UInteger
End Function' ufn : LPCWSTR
' pDn : LPWSTR* out
Declare PtrSafe Function ldap_ufn2dnW Lib "wldap32" ( _
ByVal ufn As LongPtr, _
ByVal pDn 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
ldap_ufn2dnW = ctypes.cdll.wldap32.ldap_ufn2dnW
ldap_ufn2dnW.restype = wintypes.DWORD
ldap_ufn2dnW.argtypes = [
wintypes.LPCWSTR, # ufn : LPCWSTR
ctypes.c_void_p, # pDn : LPWSTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WLDAP32.dll')
ldap_ufn2dnW = Fiddle::Function.new(
lib['ldap_ufn2dnW'],
[
Fiddle::TYPE_VOIDP, # ufn : LPCWSTR
Fiddle::TYPE_VOIDP, # pDn : LPWSTR* out
],
-Fiddle::TYPE_INT, Fiddle::Function::CDECL)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "wldap32")]
extern "C" {
fn ldap_ufn2dnW(
ufn: *const u16, // LPCWSTR
pDn: *mut *mut u16 // LPWSTR* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern uint ldap_ufn2dnW([MarshalAs(UnmanagedType.LPWStr)] string ufn, IntPtr pDn);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_ufn2dnW' -Namespace Win32 -PassThru
# $api::ldap_ufn2dnW(ufn, pDn)#uselib "WLDAP32.dll"
#func global ldap_ufn2dnW "ldap_ufn2dnW" wptr, wptr
; ldap_ufn2dnW ufn, varptr(pDn) ; 戻り値は stat
; ufn : LPCWSTR -> "wptr"
; pDn : LPWSTR* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WLDAP32.dll" #cfunc global ldap_ufn2dnW "ldap_ufn2dnW" wstr, var ; res = ldap_ufn2dnW(ufn, pDn) ; ufn : LPCWSTR -> "wstr" ; pDn : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global ldap_ufn2dnW "ldap_ufn2dnW" wstr, sptr ; res = ldap_ufn2dnW(ufn, varptr(pDn)) ; ufn : LPCWSTR -> "wstr" ; pDn : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD ldap_ufn2dnW(LPCWSTR ufn, LPWSTR* pDn) #uselib "WLDAP32.dll" #cfunc global ldap_ufn2dnW "ldap_ufn2dnW" wstr, var ; res = ldap_ufn2dnW(ufn, pDn) ; ufn : LPCWSTR -> "wstr" ; pDn : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ldap_ufn2dnW(LPCWSTR ufn, LPWSTR* pDn) #uselib "WLDAP32.dll" #cfunc global ldap_ufn2dnW "ldap_ufn2dnW" wstr, intptr ; res = ldap_ufn2dnW(ufn, varptr(pDn)) ; ufn : LPCWSTR -> "wstr" ; pDn : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procldap_ufn2dnW = wldap32.NewProc("ldap_ufn2dnW")
)
// ufn (LPCWSTR), pDn (LPWSTR* out)
r1, _, err := procldap_ufn2dnW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ufn))),
uintptr(pDn),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ldap_ufn2dnW(
ufn: PWideChar; // LPCWSTR
pDn: PPWideChar // LPWSTR* out
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_ufn2dnW';result := DllCall("WLDAP32\ldap_ufn2dnW"
, "WStr", ufn ; LPCWSTR
, "Ptr", pDn ; LPWSTR* out
, "Cdecl UInt") ; return: DWORD●ldap_ufn2dnW(ufn, pDn) = DLL("WLDAP32.dll", "dword ldap_ufn2dnW(char*, void*)")
# 呼び出し: ldap_ufn2dnW(ufn, pDn)
# ufn : LPCWSTR -> "char*"
# pDn : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "wldap32" fn ldap_ufn2dnW(
ufn: [*c]const u16, // LPCWSTR
pDn: [*c][*c]u16 // LPWSTR* out
) callconv(.c) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc ldap_ufn2dnW(
ufn: WideCString, # LPCWSTR
pDn: ptr WideCString # LPWSTR* out
): uint32 {.importc: "ldap_ufn2dnW", cdecl, dynlib: "WLDAP32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "wldap32");
extern(C)
uint ldap_ufn2dnW(
const(wchar)* ufn, // LPCWSTR
wchar** pDn // LPWSTR* out
);ccall((:ldap_ufn2dnW, "WLDAP32.dll"), UInt32,
(Cwstring, Ptr{Ptr{UInt16}}),
ufn, pDn)
# ufn : LPCWSTR -> Cwstring
# pDn : LPWSTR* out -> Ptr{Ptr{UInt16}}
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_ufn2dnW(
const uint16_t* ufn,
uint16_t** pDn);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_ufn2dnW(ufn, pDn)
-- ufn : LPCWSTR
-- pDn : 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('WLDAP32.dll');
const ldap_ufn2dnW = lib.func('__cdecl', 'ldap_ufn2dnW', 'uint32_t', ['str16', 'void *']);
// ldap_ufn2dnW(ufn, pDn)
// ufn : LPCWSTR -> 'str16'
// pDn : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WLDAP32.dll", {
ldap_ufn2dnW: { parameters: ["buffer", "pointer"], result: "u32" },
});
// lib.symbols.ldap_ufn2dnW(ufn, pDn)
// ufn : LPCWSTR -> "buffer"
// pDn : LPWSTR* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_ufn2dnW(
const uint16_t* ufn,
uint16_t** pDn);
C, "WLDAP32.dll");
// $ffi->ldap_ufn2dnW(ufn, pDn);
// ufn : LPCWSTR
// pDn : LPWSTR* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Wldap32 extends Library {
Wldap32 INSTANCE = Native.load("wldap32", Wldap32.class, W32APIOptions.UNICODE_OPTIONS);
int ldap_ufn2dnW(
WString ufn, // LPCWSTR
PointerByReference pDn // LPWSTR* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("wldap32")]
lib LibWLDAP32
fun ldap_ufn2dnW = ldap_ufn2dnW(
ufn : UInt16*, # LPCWSTR
pDn : UInt16** # LPWSTR* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ldap_ufn2dnWNative = Uint32 Function(Pointer<Utf16>, Pointer<Pointer<Utf16>>);
typedef ldap_ufn2dnWDart = int Function(Pointer<Utf16>, Pointer<Pointer<Utf16>>);
final ldap_ufn2dnW = DynamicLibrary.open('WLDAP32.dll')
.lookupFunction<ldap_ufn2dnWNative, ldap_ufn2dnWDart>('ldap_ufn2dnW');
// ufn : LPCWSTR -> Pointer<Utf16>
// pDn : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ldap_ufn2dnW(
ufn: PWideChar; // LPCWSTR
pDn: PPWideChar // LPWSTR* out
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_ufn2dnW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ldap_ufn2dnW"
c_ldap_ufn2dnW :: CWString -> Ptr CWString -> IO Word32
-- ufn : LPCWSTR -> CWString
-- pDn : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ldap_ufn2dnw =
foreign "ldap_ufn2dnW"
((ptr uint16_t) @-> (ptr (ptr uint16_t)) @-> returning uint32_t)
(* ufn : LPCWSTR -> (ptr uint16_t) *)
(* pDn : LPWSTR* out -> (ptr (ptr uint16_t)) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)
(cffi:defcfun ("ldap_ufn2dnW" ldap-ufn2dn-w :convention :cdecl) :uint32
(ufn (:string :encoding :utf-16le)) ; LPCWSTR
(p-dn :pointer)) ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ldap_ufn2dnW = Win32::API::More->new('WLDAP32',
'DWORD ldap_ufn2dnW(LPCWSTR ufn, LPVOID pDn)');
# my $ret = $ldap_ufn2dnW->Call($ufn, $pDn);
# ufn : LPCWSTR -> LPCWSTR
# pDn : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f ldap_ufn2dnA (ANSI版) — 利用者向け表記の名前をDN形式に変換する(ANSI版)。