Re: Binary byte in TCL gets pre-fixed by byte '0xC2', while accessing through C++ function via SWIG wrapper



On Jul 10, 11:59 pm, jim.cheri...@xxxxxxxxx wrote:
Hello,

I have a problem in converting a binary data into a character buffer
which is read by a C++ function using wrapper generated by SWIG.

I create a variable 'b' in TCL, and store in it a binary value as hex
string.
Then, I do "% set t [binary format H* $b]" to convert it into actual
binary.
Then, I pass it as argument to the SWIG wrapper for my C++ function,
which just accepts char* pointer and number of bytes, and prints
binary value of each separate bytes.

I can see that in my C++ function, I get 2 characters instead of 1.
My original byte is pre-fixed by a byte called 0xC2.

This happens when I pass a binary string also. Every binary byte is
pre-fixed by 0xC2.

Can some one tell me where is the problem, and how to solve it?>From TCL, it looks fine to me.

Is it a problem with SWIG wrapper doing some internal conversion?

########### See the script below ############
% load example.dll

% MyClass myObj
_e04c0a01_p_MyClass
% set b b0
b0
% set t [binary format H* $b]
°
% myObj WRAP_TestFn $t 1
[3268] WRAP_TestFn pData: 0xc2

% myObj WRAP_TestFn $t 2
[3268] WRAP_TestFn pData: 0xc2 0xb0

%
########### End ############

########### C++ code ############

void WRAP_TestFn(char* pData, unsigned int uiBufSize);

########### End ############

0xC2 0xB0 is the UTF-8 encoding of the character U+00B0 "degree sign".
You are creating a single character with value 0xB0. When this UTF-32
character is converted to a UTF-8 string, it turns into two bytes.
Are you trying to pass text to your C++ function or raw binary data?

.



Relevant Pages

  • Re: help needed on coversin of an char array to an integer
    ... Im kinda stuck in a project at a point where i need an array to ... Converting a character to it's numeric value is a ... '0' - '9' are contiguous in the character ... If you can guarantee that your character set has contiguous alphabetics ...
    (comp.lang.c)
  • Re: equal sign substituted for apostrophe
    ... apostrophe, instead of being the character from the default paragraph font, ... is a WP Typographic Symbols character. ... > One a couple of my workstations several word documents are converting an ... > apostrophe to an equal sign when the document is opened. ...
    (microsoft.public.word.application.errors)
  • Re: 4th Edition Basic Set Supers
    ... 4th Ed. PC usually need higher CP totals for ... the same powers, compared to 3rd Ed. ... If you are converting a bunch of PC to 4th Ed., ... ed.) character. ...
    (rec.games.frp.gurps)
  • Re: need to convert a char to an hexadecmial value
    ... I needed help in converting a character to the correspoding ... only an insigificant amount of data space, ... Just use int. ... , to a newline character. ...
    (comp.lang.c)
  • Re: Dual binary/character streams?
    ... >> Suppose a stream contains text and binary data. ... > character data are allowed in one "chunk" (so that you can make a copy ... don't forget that Unicode characters, unlike Java chars, are not ...
    (comp.lang.java.programmer)

Loading