Valhalla Legends Forums Archive | C/C++ Programming | Reading Files

AuthorMessageTime
l2k-Shadow
Ok, so I have a function using CreateFile() and ReadFile to read a binary file. Basically what i'm doing is storing length in the first byte of a chunk data that has to be read at once and then parsing it. A single chunk is usually 20-30 bytes long. The function is this:
[code]
__declspec(dllexport) int getclong(const char* filename, const char* temp, int mn, unsigned long* clong)
[/code]
and the part of the chunk of code used to read the file:
[code]
while (ReadFile(file, ptr, len, &read, &ol))
{
if (mn == *((BYTE*)ptr+1))
{
if (strcmp(temp, (const char*)ptr+2) == 0)
{
b = strlen(temp)+3;
*clong = *((DWORD*)ptr+b);
}
}
[/code]
The first if is fine, the second if is fine, however when i'm trying to retrieve the clong value, it returns something completely different, is this because the buffer isn't stored in line in memory, or is there something i'm doing wrong? how can i retrieve the correct value?
December 12, 2006, 5:53 AM
l2k-Shadow
hmm it appears that if i change the last parameter to a char* and return it like this, it works:
[code]
b = strlen(temp)+3;
sprintf(clong,(const char*)ptr+b);
[/code]

=/ i'll still try to find out why it doesn't work with the other way though.
December 12, 2006, 2:30 PM

Search