Board index » Visual Studio » BCSTR to Char byte value

BCSTR to Char byte value

Visual Studio114
Dear Friends,

I know it is an ordinary thing but I tried for few

times and could not find the solution, now we are having holidays here

so will be up for work a day after tomorrow but still don't know how

to do that;-)



Problem:

I have a C++ dll that uses std calls for invoking the calls and every

thing works just fine except the particular thing.



__std void foo(BCSTR str){



//I get the exact string here with the size of 6 bytes

}



The caller is VB app.



foo("A0B3C1")



In dll I receive 6 bytes that makes sense but I want the original byte

value that should be three bytes containing:

First byte : A0

Second byte : B3

Third byte : C1



Must be easy peasy but can't get it;-)





thanks

ali


-
 

Re:BCSTR to Char byte value

On Feb 19, 9:53 am, "Ali" <abdulra...@gmail.com>wrote:

Quote
Dear Friends,

I know it is an ordinary thing but I tried for few

times and could not find the solution, now we are having holidays here

so will be up for work a day after tomorrow but still don't know how

to do that;-)



Problem:

I have a C++ dll that uses std calls for invoking the calls and every

thing works just fine except the particular thing.



__std void foo(BCSTR str){



//I get the exact string here with the size of 6 bytes



}



The caller is VB app.



foo("A0B3C1")



In dll I receive 6 bytes that makes sense but I want the original byte

value that should be three bytes containing:

First byte : A0

Second byte : B3

Third byte : C1



Must be easy peasy but can't get it;-)



thanks

ali



Doh! i would hate to use a switch to make a byte out of 2 bytes;-)



ali



-

Re:BCSTR to Char byte value

"Ali" wrote:

Quote
I have a C++ dll that uses std calls for invoking the

calls and every

thing works just fine except the particular thing.



__std void foo(BCSTR str){



//I get the exact string here with the size of 6 bytes

}



The caller is VB app.



foo("A0B3C1")



In dll I receive 6 bytes that makes sense but I want the

original byte

value that should be three bytes containing:

First byte : A0

Second byte : B3

Third byte : C1





If you want to convert characters string into binary, then

look this thread, for example:



"String conversions"

groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/b99c07dba01ab0cb/4cd713dff655a9a9">groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/b99c07dba01ab0cb/4cd713dff655a9a9



HTH

Alex



-

Re:BCSTR to Char byte value

On Feb 19, 11:26 am, "Alex Blekhman" <x...@oohay.moc>wrote:

Quote
"Ali" wrote:

>I have a C++ dll that uses std calls for invoking the

>calls and every

>thing works just fine except the particular thing.



>__std void foo(BCSTR str){



>//I get the exact string here with the size of 6 bytes

>}



>The caller is VB app.



>foo("A0B3C1")



>In dll I receive 6 bytes that makes sense but I want the

>original byte

>value that should be three bytes containing:

>First byte : A0

>Second byte : B3

>Third byte : C1



If you want to convert characters string into binary, then

look this thread, for example:



"String conversions"groups.google.com/group/microsoft.public.vc.language/browse_fr...">groups.google.com/group/microsoft.public.vc.language/browse_fr...



HTH

Alex







Alex, thanks for post and sure i'll give it a try tomorrow;-)



ali



-

Re:BCSTR to Char byte value

On Feb 19, 9:39 pm, "Ali" <abdulra...@gmail.com>wrote:

Quote
On Feb 19, 11:26 am, "Alex Blekhman" <x...@oohay.moc>wrote:







>"Ali" wrote:

>>I have a C++ dll that uses std calls for invoking the

>>calls and every

>>thing works just fine except the particular thing.



>>__std void foo(BCSTR str){



>>//I get the exact string here with the size of 6 bytes

>>}



>>The caller is VB app.



>>foo("A0B3C1")



>>In dll I receive 6 bytes that makes sense but I want the

>>original byte

>>value that should be three bytes containing:

>>First byte : A0

>>Second byte : B3

>>Third byte : C1



>If you want to convert characters string into binary, then

>look this thread, for example:



>"String conversions"groups.google.com/group/microsoft.public.vc.language/browse_fr...">groups.google.com/group/microsoft.public.vc.language/browse_fr...



>HTH

>Alex



Alex, thanks for post and sure i'll give it a try tomorrow;-)



ali







Well it worked like a charm! Here is what is have done :



__stdcall int foo(LPCSTR clntip , LPCSTR clntdata , int len){



const char *ptr;

ptr = clntdata;



const char* src = ptr;

char dst[16] = { 0 };



char* p = dst;



while(*src)

{

char hi = xchtoi(*src);

++src;



if(!*src) break;



char lo = xchtoi(*src);

++src;



*p = (hi << 4) | lo;

++p;

}



//dst is ready to eat;-)



return 0;

}//__stdcall int foo(LPCSTR clntip , LPCSTR clntdata)







Now I VB app is calling f00 such as :

foo("2354ab");



And in my dll i can see the three bytes containg 23, 54 and ab.



Alex, thanks for this handy piece of code.

ali



-