Link to home
Start Free TrialLog in
Avatar of ashwini
ashwini

asked on

length of a string containing binary data

I have a BYTE *str;
In this BYTE string I am storing binary data which may contain many null terminating characters.
Functions like strlen and sysstringlen return the length of the string till the first found null terminating character.
I want to find the entire length of the string.
How do I do that????

NOTE:-
I am not using win32 APIs.
I am using COM language.
Avatar of ashwini
ashwini

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ashwini

ASKER

If the string data is coming from some other way,say from a dtatabase,then how do I go to the end of the data string and append a EOS character.

The problem is that how do I know that the binary data is ending at a particular position in the string.
Avatar of ashwini

ASKER

Can I know how many bytes are dynamically allocated to the BYTE *str in which the binary data is stored????????
no
Avatar of ozo
How do you dynamically allocate BYTE *str?
Avatar of ashwini

ASKER

What I want to do is that somehow I want to strore this data coming from a database in a BYTE * variable.For this I first want to know the length of the data coming to me and accordingly strore it in the variable.After this I want to store the length in a different variable and send it to some other method.


Avatar of ashwini

ASKER

The data coming to me can be less than or equal to 60000 bytes.
How is the data coming from a database?
Avatar of ashwini

ASKER

The data comes through a socket.
If there data is Variable Lenght format, they have standart
structure: Len (usually 2 b), Data (Len baits).
Avatar of ashwini

ASKER

Yes
Sorry, ashwini, what means "Yes"? Is my reply right?
(in this case you must accept reply) or something else?
Avatar of ashwini

ASKER

AlexVirochovsky,

Can you please clarify your answer.
A small piece of code would suffice.

I didn't get what you replied.

Regards
Jasmina
If i uderstand right, you want clarify reply about
Variable Lenght Format?
Well, records of such form can be builded in structure:
Len (2 b usually), text. Can be some variants:
For example, record can be from some fields.
In such case will number of fields,
and in Loop by number of fields : len of field, field.
All this depends of database, that you work with.
Example of code for 2-nd case
....
char *buff;  //input buffer
short nNumFields;//number of fields
memcpy(&nNumFields, buff,2);
char *ptr = buff+2;
char *MyString;//result
for (int i = 0; i < nNumFields; i++)
  {
    short nLen;
    memcmp(nLen, ptr,2); ptr += 2;
    strncpy(MyString, ptr,nLen);
    ptr += nLen;
  }
....
I hope(to 50%), that it helps. )-:
Alex