Re: Binary byte in TCL gets pre-fixed by byte '0xC2', while accessing through C++ function via SWIG wrapper
- From: billposer@xxxxxxxxxxxx
- Date: Wed, 11 Jul 2007 09:44:10 -0000
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?
.
- References:
- Prev by Date: Tkcon exit status
- Next by Date: problems grasping tcl threads
- Previous by thread: Binary byte in TCL gets pre-fixed by byte '0xC2', while accessing through C++ function via SWIG wrapper
- Next by thread: Re: Binary byte in TCL gets pre-fixed by byte '0xC2', while accessing through C++ function via SWIG wrapper
- Index(es):
Relevant Pages
|
Loading