CryptoSys PKI Pro Manual

CNV_HexStrFromBytes

Encodes an array of bytes into a hexadecimal-encoded string.

VBA/VB6 Syntax

Public Declare Function CNV_HexStrFromBytes Lib "diCrPKI.dll" (ByVal strHex As String, ByVal nHexStrLen As Long, ByRef lpData As Byte, ByVal nDataLen As Long) As Long

nRet = CNV_HexStrFromBytes(strHex, nHexStrLen, lpData(0), nDataLen)

C/C++ Syntax

long __stdcall CNV_HexStrFromBytes(char *szOutput, long nOutChars, const unsigned char *lpInput, long nInputLen);

Parameters

szOutput
[out] to receive encoded data.
nOutChars
[in] specifying the maximum number of characters to be received.
lpInput
[in] array of binary data to be encoded.
nInputLen
[in] number of bytes to be encoded.

Returns (VBA/C)

If successful, the return value is the number of characters in the encoded string; otherwise it returns a negative error code.

VBA Wrapper Syntax

Public Function cnvHexFromBytesMid (abData() As Byte, nOffset As Long, nBytes As Long) As String
Public Function cnvHexStrFromB64Str (szB64 As String) As String
Public Function cnvHexStrFromBytes (lpData() As Byte) As String
Public Function cnvHexStrFromString (szData As String) As String
Public Function cnvToHex (lpData() As Byte) As String

.NET Equivalent

Cnv.ToHex Method

C++ (STL) Equivalent

static std::string dipki::Cnv::ToHex (const bvec_t &bv)
static std::string dipki::Cnv::ToHex (const std::string &s)

Python Equivalent

static Cnv.tohex(data)

Remarks

Specify a zero nOutChars or an empty string for szOutput to find the required length of the output string. ANSI C users must add one to this value when allocating memory.

The input array may contain bytes of any value. If vbNullString or an empty string ("") is specified for szHex or zero for nHexStrLen, the function will return the maximum possible size of the encoded string. The final result may be smaller. C/C++ programmers should add one to the returned length value when allocating memory.

Example (VBA core function)

The following wrapper function returns an encoded string directly. Note that if abData is empty then UBound(abData) will raise a runtime error. So we trap the error and return the default empty string.

Public Function cnvHexStrFromBytes(abData() As Byte) As String
' Returns hex string encoding of bytes in abData or empty string on error
    Dim strHex As String
    Dim nHexLen As Long
    Dim nDataLen As Long
    
    On Error GoTo CatchEmptyData
    nDataLen = UBound(abData) - LBound(abData) + 1
    nHexLen = CNV_HexStrFromBytes(vbNullString, 0, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    strHex = String$(nHexLen, " ")
    nHexLen = CNV_HexStrFromBytes(strHex, nHexLen, abData(0), nDataLen)
    If nHexLen <= 0 Then
        Exit Function
    End If
    cnvHexStrFromBytes = Left$(strHex, nHexLen)
    
CatchEmptyData:

End Function

See Also

CNV_BytesFromHexStr CNV_HexFilter

[Contents] [Index]

[PREV: CNV_HexFilter...]   [Contents]   [Index]   
   [NEXT: CNV_Latin1FromUTF8...]

Copyright © 2004-24 D.I. Management Services Pty Ltd. All rights reserved. Generated 2024-09-23T07:52:09Z.