Decodes a hexadecimal-encoded string into an array of Bytes.
Public Declare Function CNV_BytesFromHexStr Lib "diCrPKI.dll"
(ByRef abData As Byte, ByVal nDataLen As Long, ByVal strHex As String) As Long
nLen = CNV_BytesFromHexStr(abData(0), nDataLen, strHex)
Byte array suitably dimensioned to receive output.Long specifying the length of the byte array.String of hexadecimal data to be decoded.
long _stdcall CNV_BytesFromHexStr(unsigned char *output, long out_len, const char *input);
Long: If successful, the return value is the number of bytes in the decoded array;
otherwise it returns a negative error code.
Call the function with an empty array to find the required length.
Wrapper function to return byte-array (as a Variant) directly:-
Public Function cnvBytesFromHexStr(strHex As String) As Variant
Dim abData() As Byte
Dim nDataLen As Long
Dim nHexLen As Long
cnvBytesFromHexStr = abData
nDataLen = CNV_BytesFromHexStr(0, 0, strHex)
If nDataLen <= 0 Then
Exit Function
End If
ReDim abData(nDataLen - 1)
nDataLen = CNV_BytesFromHexStr(abData(0), nDataLen, strHex)
ReDim Preserve abData(nDataLen - 1)
cnvBytesFromHexStr = abData
End Function
CNV_HexStrFromBytes CNV_HexFilter