Encodes an array of bytes into a hexadecimal-encoded string.
Public Declare Function CNV_HexStrFromBytes Lib "diCrPKI.dll"
(ByVal strHex As String, ByVal nHexStrLen As Long,
ByRef abData As Byte, ByVal nDataLen As Long) As Long
nRet = CNV_HexStrFromBytes(strHex, nHexStrLen, abData(0), nDataLen)
String to receive encoded data.Long specifying the maximum number of characters to be received.Byte array of binary data to be encoded.Long number of bytes to be encoded.
long _stdcall CNV_HexStrFromBytes(char *szOutput, long nOutChars, const unsigned char *input, long nbytes);
Long: If successful, the return value is the number of characters in the encoded string;
otherwise it returns a negative error code.
The input array may contain bytes of any value.
If vbNullString or an empty string ("") is specified for strHex 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.
This wrapper function returns an encoded string directly:
Public Function cnvHexStrFromBytes(abData() As Byte) As String
On Error GoTo CatchEmptyData
Dim strHex As String
Dim nHexLen As Long
Dim nDataLen As Long
nDataLen = UBound(abData) - LBound(abData) + 1
nHexLen = CNV_HexStrFromBytes("", 0, abData(0), nDataLen)
If nHexLen <= 0 Then
Exit Function
End If
strHex = String$(nHexLen, " ")
nHexLen = CNV_HexStrFromBytes(strHex, nHexLen, abData(0), nDataLen)
cnvHexStrFromBytes = Left$(strHex, nHexLen)
CatchEmptyData:
End Function
CNV_BytesFromHexStr CNV_HexFilter