ホーム › Networking.Ldap › LdapUTF8ToUnicode
LdapUTF8ToUnicode
関数UTF-8文字列をUnicode文字列に変換する。
シグネチャ
// WLDAP32.dll
#include <windows.h>
INT LdapUTF8ToUnicode(
LPCSTR lpSrcStr,
INT cchSrc,
LPWSTR lpDestStr,
INT cchDest
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpSrcStr | LPCSTR | in |
| cchSrc | INT | in |
| lpDestStr | LPWSTR | out |
| cchDest | INT | in |
戻り値の型: INT
各言語での呼び出し定義
// WLDAP32.dll
#include <windows.h>
INT LdapUTF8ToUnicode(
LPCSTR lpSrcStr,
INT cchSrc,
LPWSTR lpDestStr,
INT cchDest
);[DllImport("WLDAP32.dll", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int LdapUTF8ToUnicode(
[MarshalAs(UnmanagedType.LPStr)] string lpSrcStr, // LPCSTR
int cchSrc, // INT
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpDestStr, // LPWSTR out
int cchDest // INT
);<DllImport("WLDAP32.dll", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function LdapUTF8ToUnicode(
<MarshalAs(UnmanagedType.LPStr)> lpSrcStr As String, ' LPCSTR
cchSrc As Integer, ' INT
<MarshalAs(UnmanagedType.LPWStr)> lpDestStr As System.Text.StringBuilder, ' LPWSTR out
cchDest As Integer ' INT
) As Integer
End Function' lpSrcStr : LPCSTR
' cchSrc : INT
' lpDestStr : LPWSTR out
' cchDest : INT
Declare PtrSafe Function LdapUTF8ToUnicode Lib "wldap32" ( _
ByVal lpSrcStr As String, _
ByVal cchSrc As Long, _
ByVal lpDestStr As LongPtr, _
ByVal cchDest As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LdapUTF8ToUnicode = ctypes.cdll.wldap32.LdapUTF8ToUnicode
LdapUTF8ToUnicode.restype = ctypes.c_int
LdapUTF8ToUnicode.argtypes = [
wintypes.LPCSTR, # lpSrcStr : LPCSTR
ctypes.c_int, # cchSrc : INT
wintypes.LPWSTR, # lpDestStr : LPWSTR out
ctypes.c_int, # cchDest : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WLDAP32.dll')
LdapUTF8ToUnicode = Fiddle::Function.new(
lib['LdapUTF8ToUnicode'],
[
Fiddle::TYPE_VOIDP, # lpSrcStr : LPCSTR
Fiddle::TYPE_INT, # cchSrc : INT
Fiddle::TYPE_VOIDP, # lpDestStr : LPWSTR out
Fiddle::TYPE_INT, # cchDest : INT
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "wldap32")]
extern "C" {
fn LdapUTF8ToUnicode(
lpSrcStr: *const u8, // LPCSTR
cchSrc: i32, // INT
lpDestStr: *mut u16, // LPWSTR out
cchDest: i32 // INT
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WLDAP32.dll", SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int LdapUTF8ToUnicode([MarshalAs(UnmanagedType.LPStr)] string lpSrcStr, int cchSrc, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpDestStr, int cchDest);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_LdapUTF8ToUnicode' -Namespace Win32 -PassThru
# $api::LdapUTF8ToUnicode(lpSrcStr, cchSrc, lpDestStr, cchDest)#uselib "WLDAP32.dll"
#func global LdapUTF8ToUnicode "LdapUTF8ToUnicode" sptr, sptr, sptr, sptr
; LdapUTF8ToUnicode lpSrcStr, cchSrc, varptr(lpDestStr), cchDest ; 戻り値は stat
; lpSrcStr : LPCSTR -> "sptr"
; cchSrc : INT -> "sptr"
; lpDestStr : LPWSTR out -> "sptr"
; cchDest : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WLDAP32.dll" #cfunc global LdapUTF8ToUnicode "LdapUTF8ToUnicode" str, int, var, int ; res = LdapUTF8ToUnicode(lpSrcStr, cchSrc, lpDestStr, cchDest) ; lpSrcStr : LPCSTR -> "str" ; cchSrc : INT -> "int" ; lpDestStr : LPWSTR out -> "var" ; cchDest : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global LdapUTF8ToUnicode "LdapUTF8ToUnicode" str, int, sptr, int ; res = LdapUTF8ToUnicode(lpSrcStr, cchSrc, varptr(lpDestStr), cchDest) ; lpSrcStr : LPCSTR -> "str" ; cchSrc : INT -> "int" ; lpDestStr : LPWSTR out -> "sptr" ; cchDest : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT LdapUTF8ToUnicode(LPCSTR lpSrcStr, INT cchSrc, LPWSTR lpDestStr, INT cchDest) #uselib "WLDAP32.dll" #cfunc global LdapUTF8ToUnicode "LdapUTF8ToUnicode" str, int, var, int ; res = LdapUTF8ToUnicode(lpSrcStr, cchSrc, lpDestStr, cchDest) ; lpSrcStr : LPCSTR -> "str" ; cchSrc : INT -> "int" ; lpDestStr : LPWSTR out -> "var" ; cchDest : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT LdapUTF8ToUnicode(LPCSTR lpSrcStr, INT cchSrc, LPWSTR lpDestStr, INT cchDest) #uselib "WLDAP32.dll" #cfunc global LdapUTF8ToUnicode "LdapUTF8ToUnicode" str, int, intptr, int ; res = LdapUTF8ToUnicode(lpSrcStr, cchSrc, varptr(lpDestStr), cchDest) ; lpSrcStr : LPCSTR -> "str" ; cchSrc : INT -> "int" ; lpDestStr : LPWSTR out -> "intptr" ; cchDest : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procLdapUTF8ToUnicode = wldap32.NewProc("LdapUTF8ToUnicode")
)
// lpSrcStr (LPCSTR), cchSrc (INT), lpDestStr (LPWSTR out), cchDest (INT)
r1, _, err := procLdapUTF8ToUnicode.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpSrcStr))),
uintptr(cchSrc),
uintptr(lpDestStr),
uintptr(cchDest),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction LdapUTF8ToUnicode(
lpSrcStr: PAnsiChar; // LPCSTR
cchSrc: Integer; // INT
lpDestStr: PWideChar; // LPWSTR out
cchDest: Integer // INT
): Integer; cdecl;
external 'WLDAP32.dll' name 'LdapUTF8ToUnicode';result := DllCall("WLDAP32\LdapUTF8ToUnicode"
, "AStr", lpSrcStr ; LPCSTR
, "Int", cchSrc ; INT
, "Ptr", lpDestStr ; LPWSTR out
, "Int", cchDest ; INT
, "Cdecl Int") ; return: INT●LdapUTF8ToUnicode(lpSrcStr, cchSrc, lpDestStr, cchDest) = DLL("WLDAP32.dll", "int LdapUTF8ToUnicode(char*, int, char*, int)")
# 呼び出し: LdapUTF8ToUnicode(lpSrcStr, cchSrc, lpDestStr, cchDest)
# lpSrcStr : LPCSTR -> "char*"
# cchSrc : INT -> "int"
# lpDestStr : LPWSTR out -> "char*"
# cchDest : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。