I did a pretty thorough search for this but didnt come up with anything but strstr and memchr functions. I am trying to search for a 4 byte string in a memory area created with GlobalAlloc and ReadFile.
I created a function with two parameter for a pointer to memory and size. In my loop I'm getting conversion errors of char * to char[4] and such. I also type casted the FileSize as int to get rid of erros with conversions to int since that is what I want to do (I think).
1 2 3 4 5 6 7 8 9 10
int FindPOL2(char *lpBuffer, LPDWORD FileSize) {
char POL2[4] = {'P','O','L','2'};
char buffer[4];
for (int i=0; i<=(int)FileSize-4;i++){
if (*(lpBuffer+i) == POL2){
return i;
}
}
return -1;
}
My real question is: since buffer[4] is 4 bytes, why doesn't *(lpBuffer+i) return just 4 bytes? Or am I going to have to do lstrcmp here?
Albeit longer, this in assembly is so much easier.
PanGalactic: Thanks for the info about what I was writing. Most of my "c++" knowledge has been from looking at others examples. I though that was more or less a standard way to do things with pointers.
jsmith: eventually the buffer is going to be at least a megabyte in size with multiple POL2 sections. And I didn't want to use string library because from what I can tell it will stop at the first Null byte it finds (or is that specifically C strings?)
Galik: Thanks for that code snipplet, I found the search function in the Cstring.h file. I'll test this out later today.
Only cstrings are null terminated. std::string can contain nulls as normal values. Also the std::search() function is in the <algorithms> header. I included <cstring> to get strlen();