471,310 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,310 software developers and data experts.

Encoding conversions

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

Aug 11 '05 #1
0 947

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Edward K. Ream | last post: by
14 posts views Thread by Sebastian Meyer | last post: by
10 posts views Thread by Christopher H. Laco | last post: by
reply views Thread by joseph speigle | last post: by
4 posts views Thread by Christina | last post: by
2 posts views Thread by joakim.hove | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.