I have an unmanaged dll that decrypts some encrypted text read out of a 2D
Barcode
This decryption function fails gracefully with a message that it could not
get the decoded string. the string is partially decoded but looks like it has
droped out half way through after ecountering an illegal character or
something. I also have a third party standalone app written in C++ that
decrypts the barcode successfully using all the same versions of dlls etc I
am using in .net. I am tryinig to unwrap this app and incorporate the
functionality in a more managed way into my systems (With the software
vendors permision) .
I have spoken to the software vendor and they have suggested that there may
be a problem with the unicode string that I am passing in and the array of
unsigned characters that the native C++ app passes in.
My API definition and call look like this
Private Declare Function ARCED_decode Lib "DecoderCD.dll" Alias
"_ARCED_decode@28" _
(ByVal encodeString As StringBuilder, ByVal mailerID As
StringBuilder, _
ByVal mailerRef As StringBuilder, ByVal decodeString As
StringBuilder, _
ByRef pMailerRefLen As Integer, ByVal maxSize As Integer, _
ByVal errStr As StringBuilder) As Integer
Sub Main()
Dim _encodeBuf As New StringBuilder(255)
Dim _decodeBuf As New StringBuilder(255)
Dim _decodebufLen As Integer
Dim _mailerRefBuf As New StringBuilder(255)
Dim _mailerRefBufLen As Integer
Dim _mailerIDbuf As New StringBuilder(10)
Dim _errorBuf As New StringBuilder(255)
_encodeBuf.Append(ReadBarcode)
_decodebufLen = ARCED_decode(_encodeBuf, _mailerIDbuf,
_mailerRefBuf, _decodeBuf, _mailerRefBufLen, _encodeBuf.Capacity + 1,
_errorBuf)
End Sub
I have attemped to convert from unicode bytes to an array of bytes of
various encodings filling my string builders with these like this
Public Function ConvertToUTF8(ByVal EncodeString As String) As StringBuilder
Dim _UTF8Encoding As New UTF8Encoding
Dim _UnicodeEncoding As New UnicodeEncoding
Dim _UnicodeBytes() As Byte = _UnicodeEncoding.GetBytes(EncodeString)
Dim _UTF8Bytes() As Byte =
_UnicodeEncoding.Convert(_UnicodeEncoding, _UTF8Encoding, _UTF8Bytes)
Dim _sb as New Stringbuilder(255)
For each UTF8Byte As Byte in _UTF8Bytes
_sb.Append(UTF88yte)
Next
Return _sb
End Function
Below is a C++ code snippet from a sample sent to me by the software vendor
of how their app builds up its char array
unsigned char encodeBuf[256];
int encodeBufLen = bars[i]->DataString->Length;
for (int j = 0; j < encodeBufLen; j++)
{
encodeBuf[j] = (unsigned char)bars[i]->DataString->get_Chars(j);
// printf ("%d ", encodeBuf[j]);
}
I cannot work out
a) what encoding is equivilent to the Unsigned Char (although I suspect UTF8)
b) whether I have done th job properly (obviously not 'cos it don't work)
c) if i am barking up the wrong tree and there is some other problem.
Any suggestion greatly appreciated
Cheers
Ben