CertRDNValueToStr

The CertRDNValueToStr function converts a Name Value to a zero-terminated character string.

#include <wincrypt.h>
DWORD WINAPI CertRDNValueToStr(
  DWORD dwValueType,            // in
  PCERT_RDN_VALUE_BLOB pValue,  // in
  LPTSTR pszValueString,        // out, optional
  DWORD cszValueString          // in
);
 

Parameters

dwValueType
The value type can be any one of the following:
CERT_RDN_ANY_TYPE
CERT_RDN_ENCODED_BLOB
CERT_RDN_OCTET_STRING
CERT_RDN_NUMERIC_STRING
CERT_RDN_PRINTABLE_STRING
CERT_RDN_TELETEX_STRING
CERT_RDN_T61_STRING
CERT_RDN_VIDEOTEX_STRING
CERT_RDN_IA5_STRING
CERT_RDN_GRAPHIC_STRING
CERT_RDN_VISIBLE_STRING
CERT_RDN_ISO646_STRING
CERT_RDN_GENERAL_STRING
CERT_RDN_UNIVERSAL_STRING
CERT_RDN_INT4_STRING
CERT_RDN_BMP_STRING
CERT_RDN_UNICODE_STRING

pValue
A pointer to an CERT_RDN_VALUE_BLOB that is of a type appropriate for the dwValueType. See BLOB Structure.
pszValueString
The address for the returned string.
cszValueString
The size, in characters, allocated for the returned string.

Return Values

Returns the number of characters converted, including the terminating zero character. If pszValueString is NULL or cszValueString is zero, returns the required size of the destination string.

Remarks

If pszValueString is not NULL and cszValueString is not zero, the returned pszValueString is always zero terminated.

Example

// EXAMPLE CODE FOR USING CertRDNValueToStr.
// Converts a Name Value to a zero-terminated character string.
// Assume that a pointer to the PCERT_RDN_VALUE_BLOB (pValue) 
// for which the intended attributes are being compared is
// already known.

// Set up the variables.
DWORD dwValueType = CERT_RDN_ANY_TYPE;
                              // Value type
PCERT_RDN_VALUE_BLOB pValue;  // Initialized elsewhere
LPTSTR pszValueString;        // Address of returned string.
                              //   NULL returns the required size of
                              //   the string 
DWORD cszValueString;         // Size, in characters, for the returned
                              //   string
DWORD dwResult;               // Returned value is # of characters
                              //   converted or required size

// Function called the first time to get
// the size of cszValueString
dwResult = CertRDNValueToStr(
             dwValueType,     // in - Any 1 of 17 value types
             pValue,          // in - Pointer for the
                              //    CERT_RDN_VALUE_BLOB
             NULL,            // NULL on the first call
             0);              // 0 on the first call

if (dwResult == 0) {          // Failure
  cout<< " first call to CertRDNValueToStr failed"<< endl;
}
else {
  cout<< " first call to CertRDNValueToStr successful"<< endl;
  pszValueString = (LPTSTR) malloc (cszValueString);
  cout<< "memory allocated"<< endl;
}

// Function call to convert name to string
dwResult = CertRDNValueToStr(
             dwValueType,     // in - Any 1 of 17 value types
             pValue,          // in - Pointer for the LPTSTR
             pszValueString,  // out- optional -
                              //   Address of string allocation
             cszValueString); // in - Size of the retuned string 


cout<< "# of characters converted = "<< dwResult<< endl
  << "Converted String =" << pszValueString<< endl;
free (pValue);
 

QuickInfo

  Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
  Windows: Requires Windows 98 (or Windows 95 with IE 3.02 or later).
  Windows CE: Unsupported.
  Header: Declared in wincrypt.h.
  Import Library: Use crypt32.lib.
  Unicode: Defined as Unicode and ANSI prototypes.

See Also

CertNameToStr