Win32 API 日本語リファレンス
ホームSecurity.Cryptography › CertNameToStrW

CertNameToStrW

関数
エンコードされた証明書名をUnicodeのX.500文字列に変換する。
DLLCRYPT32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows XP 以降

シグネチャ

// CRYPT32.dll  (Unicode / -W)
#include <windows.h>

DWORD CertNameToStrW(
    CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
    CRYPT_INTEGER_BLOB* pName,
    CERT_STRING_TYPE dwStrType,
    LPWSTR psz,   // optional
    DWORD csz
);

パラメーター

名前方向
dwCertEncodingTypeCERT_QUERY_ENCODING_TYPEin
pNameCRYPT_INTEGER_BLOB*in
dwStrTypeCERT_STRING_TYPEin
pszLPWSTRoutoptional
cszDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// CRYPT32.dll  (Unicode / -W)
#include <windows.h>

DWORD CertNameToStrW(
    CERT_QUERY_ENCODING_TYPE dwCertEncodingType,
    CRYPT_INTEGER_BLOB* pName,
    CERT_STRING_TYPE dwStrType,
    LPWSTR psz,   // optional
    DWORD csz
);
[DllImport("CRYPT32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint CertNameToStrW(
    uint dwCertEncodingType,   // CERT_QUERY_ENCODING_TYPE
    IntPtr pName,   // CRYPT_INTEGER_BLOB*
    uint dwStrType,   // CERT_STRING_TYPE
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder psz,   // LPWSTR optional, out
    uint csz   // DWORD
);
<DllImport("CRYPT32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CertNameToStrW(
    dwCertEncodingType As UInteger,   ' CERT_QUERY_ENCODING_TYPE
    pName As IntPtr,   ' CRYPT_INTEGER_BLOB*
    dwStrType As UInteger,   ' CERT_STRING_TYPE
    <MarshalAs(UnmanagedType.LPWStr)> psz As System.Text.StringBuilder,   ' LPWSTR optional, out
    csz As UInteger   ' DWORD
) As UInteger
End Function
' dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
' pName : CRYPT_INTEGER_BLOB*
' dwStrType : CERT_STRING_TYPE
' psz : LPWSTR optional, out
' csz : DWORD
Declare PtrSafe Function CertNameToStrW Lib "crypt32" ( _
    ByVal dwCertEncodingType As Long, _
    ByVal pName As LongPtr, _
    ByVal dwStrType As Long, _
    ByVal psz As LongPtr, _
    ByVal csz As Long) 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

CertNameToStrW = ctypes.windll.crypt32.CertNameToStrW
CertNameToStrW.restype = wintypes.DWORD
CertNameToStrW.argtypes = [
    wintypes.DWORD,  # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
    ctypes.c_void_p,  # pName : CRYPT_INTEGER_BLOB*
    wintypes.DWORD,  # dwStrType : CERT_STRING_TYPE
    wintypes.LPWSTR,  # psz : LPWSTR optional, out
    wintypes.DWORD,  # csz : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CRYPT32.dll')
CertNameToStrW = Fiddle::Function.new(
  lib['CertNameToStrW'],
  [
    -Fiddle::TYPE_INT,  # dwCertEncodingType : CERT_QUERY_ENCODING_TYPE
    Fiddle::TYPE_VOIDP,  # pName : CRYPT_INTEGER_BLOB*
    -Fiddle::TYPE_INT,  # dwStrType : CERT_STRING_TYPE
    Fiddle::TYPE_VOIDP,  # psz : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # csz : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "crypt32")]
extern "system" {
    fn CertNameToStrW(
        dwCertEncodingType: u32,  // CERT_QUERY_ENCODING_TYPE
        pName: *mut CRYPT_INTEGER_BLOB,  // CRYPT_INTEGER_BLOB*
        dwStrType: u32,  // CERT_STRING_TYPE
        psz: *mut u16,  // LPWSTR optional, out
        csz: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CRYPT32.dll", CharSet = CharSet.Unicode)]
public static extern uint CertNameToStrW(uint dwCertEncodingType, IntPtr pName, uint dwStrType, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder psz, uint csz);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CRYPT32_CertNameToStrW' -Namespace Win32 -PassThru
# $api::CertNameToStrW(dwCertEncodingType, pName, dwStrType, psz, csz)
#uselib "CRYPT32.dll"
#func global CertNameToStrW "CertNameToStrW" wptr, wptr, wptr, wptr, wptr
; CertNameToStrW dwCertEncodingType, varptr(pName), dwStrType, varptr(psz), csz   ; 戻り値は stat
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "wptr"
; pName : CRYPT_INTEGER_BLOB* -> "wptr"
; dwStrType : CERT_STRING_TYPE -> "wptr"
; psz : LPWSTR optional, out -> "wptr"
; csz : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "CRYPT32.dll"
#cfunc global CertNameToStrW "CertNameToStrW" int, var, int, var, int
; res = CertNameToStrW(dwCertEncodingType, pName, dwStrType, psz, csz)
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int"
; pName : CRYPT_INTEGER_BLOB* -> "var"
; dwStrType : CERT_STRING_TYPE -> "int"
; psz : LPWSTR optional, out -> "var"
; csz : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD CertNameToStrW(CERT_QUERY_ENCODING_TYPE dwCertEncodingType, CRYPT_INTEGER_BLOB* pName, CERT_STRING_TYPE dwStrType, LPWSTR psz, DWORD csz)
#uselib "CRYPT32.dll"
#cfunc global CertNameToStrW "CertNameToStrW" int, var, int, var, int
; res = CertNameToStrW(dwCertEncodingType, pName, dwStrType, psz, csz)
; dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "int"
; pName : CRYPT_INTEGER_BLOB* -> "var"
; dwStrType : CERT_STRING_TYPE -> "int"
; psz : LPWSTR optional, out -> "var"
; csz : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	crypt32 = windows.NewLazySystemDLL("CRYPT32.dll")
	procCertNameToStrW = crypt32.NewProc("CertNameToStrW")
)

// dwCertEncodingType (CERT_QUERY_ENCODING_TYPE), pName (CRYPT_INTEGER_BLOB*), dwStrType (CERT_STRING_TYPE), psz (LPWSTR optional, out), csz (DWORD)
r1, _, err := procCertNameToStrW.Call(
	uintptr(dwCertEncodingType),
	uintptr(pName),
	uintptr(dwStrType),
	uintptr(psz),
	uintptr(csz),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function CertNameToStrW(
  dwCertEncodingType: DWORD;   // CERT_QUERY_ENCODING_TYPE
  pName: Pointer;   // CRYPT_INTEGER_BLOB*
  dwStrType: DWORD;   // CERT_STRING_TYPE
  psz: PWideChar;   // LPWSTR optional, out
  csz: DWORD   // DWORD
): DWORD; stdcall;
  external 'CRYPT32.dll' name 'CertNameToStrW';
result := DllCall("CRYPT32\CertNameToStrW"
    , "UInt", dwCertEncodingType   ; CERT_QUERY_ENCODING_TYPE
    , "Ptr", pName   ; CRYPT_INTEGER_BLOB*
    , "UInt", dwStrType   ; CERT_STRING_TYPE
    , "Ptr", psz   ; LPWSTR optional, out
    , "UInt", csz   ; DWORD
    , "UInt")   ; return: DWORD
●CertNameToStrW(dwCertEncodingType, pName, dwStrType, psz, csz) = DLL("CRYPT32.dll", "dword CertNameToStrW(dword, void*, dword, char*, dword)")
# 呼び出し: CertNameToStrW(dwCertEncodingType, pName, dwStrType, psz, csz)
# dwCertEncodingType : CERT_QUERY_ENCODING_TYPE -> "dword"
# pName : CRYPT_INTEGER_BLOB* -> "void*"
# dwStrType : CERT_STRING_TYPE -> "dword"
# psz : LPWSTR optional, out -> "char*"
# csz : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。