PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PPC Emulator SetFilePointer

I am writing because I am having a problem I wasn´t able to resolve.

I am using the SetFilePointer function in my mobile project. The problem arise when I try to test it in my emulator. The SetFilePointer function moves its pointer in the oposite direction. When I pass a positive value to the method, the file pointer moves backward. And when I pass it a negative one, it moves foward. This only happens when the dwMoveMethod it´s set to FILE_END.

When I run the program in my ppc it works fine, just like the documentation explain.

Maybe I am doing something wrong, does anybody have the same problem. I try to search in the forum and no post for SetFilePointer was found. Also, I not sure if this is the right forum to post.

My emulators are,

The windows ce emulator for pocket pc 2003 and the
Microsoft Device Emulator for WM2005

The file SOMETHING.zip it´s a 170 byte file. So I try this code, with 70 and with -300. The first one returns a pointer with 100 and the second a pointer with 470. I am adding some code.

Code:

HANDLE mifile = CreateFile(TEXT("/STORAGE CARD/SOMETHING.zip"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
DWORD pointer = SetFilePointer(mifile, 70, NULL, FILE_END);
We have just receive an answer from microsoft about this subject.

There is a Device Emulator BSP bug in the SetFilePointer function for emulators when the FILE_END variable is sent.

Regards

Octavio
Workaround:
Code:

// replace every
SetFilePointer(hFile, offset, NULL, FILE_END);
// with
DWORD fileSize = GetFileSize(hFile, NULL);
SetFilePointer(hFile, fileSize + offset, NULL, FILE_BEGIN);

I've run into this problem with the WM5 emulator recently. We've got no WM5 device and I couldn't avoid testing on the emulator. So, I dropped FILE_END completely and used the above method to simulate its CORRECT behavior. Since there was (luckily ;)) a simple File class around bare file API calls, it wasn't much pain to do.
Does this affect the std fopen api as well? I seldom use Win32 file APIs unless absolutely necessary (like specifying no caching for writing) for portability reasons.

Dan East
Yes, both fseek(SEEK_END) and CFile::Seek(CFile::end) behave the same perverted way as SetFilePointer(FILE_END). Microsoft surely cares much about consistency ;).