Lewis_Miller
February 23rd, 2005, 10:35 AM
Hi all,
Im trying to create a string that is an ansi like (single char) version of a bstr. if i understand it correctly a bstr is conceptually laid out in memory with tchar's and the first 2 tchar's are the length, as in:
in bytes: length \0\0\0\0 | data (tchar's) |null \0\0
or in tchars: length str[0] str[1] | data str[2]...str[n] | null str[last]
and the bstr variable actually points to str[2] .
what im attempting to do is create a similar version that uses single bytes (as opposed to tchar's)... something like this:
length (unsigned long) \0\0\0\0 | null terminated c string
the problem im having is finding syntax to set/get the length in the first four bytes with the length of the remaining data (minus the null) i tried to use the kernel function MoveMemory to copy the length into the first four bytes but it seems to wipe out the rest of the string. Ive tried somethign like this:
typedef ubyte unsigned char
ubyte *loadstr(const char *s,int length) {
ubyte * snew = (ubyte *)malloc(length +5);
if (s) {
//how to set length here?
//RtlMoveMemory(&s,&snew,4);
int i = 5;
while (s) {
*snew[i] = (ubyte)*s++;
i++;
}
}
return &snew[5];
}
any help or pointers in the right direction would be much appreciated.
Regards
Lewis
Im trying to create a string that is an ansi like (single char) version of a bstr. if i understand it correctly a bstr is conceptually laid out in memory with tchar's and the first 2 tchar's are the length, as in:
in bytes: length \0\0\0\0 | data (tchar's) |null \0\0
or in tchars: length str[0] str[1] | data str[2]...str[n] | null str[last]
and the bstr variable actually points to str[2] .
what im attempting to do is create a similar version that uses single bytes (as opposed to tchar's)... something like this:
length (unsigned long) \0\0\0\0 | null terminated c string
the problem im having is finding syntax to set/get the length in the first four bytes with the length of the remaining data (minus the null) i tried to use the kernel function MoveMemory to copy the length into the first four bytes but it seems to wipe out the rest of the string. Ive tried somethign like this:
typedef ubyte unsigned char
ubyte *loadstr(const char *s,int length) {
ubyte * snew = (ubyte *)malloc(length +5);
if (s) {
//how to set length here?
//RtlMoveMemory(&s,&snew,4);
int i = 5;
while (s) {
*snew[i] = (ubyte)*s++;
i++;
}
}
return &snew[5];
}
any help or pointers in the right direction would be much appreciated.
Regards
Lewis