PocketMatrix forums

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

FILE operations

hello, i just created a logfile class for the pocketpc. im using c file i/o.
fopen( filename, "w" ), fwrite, fread, fclose

well the thing is i init this logfile first thing in the program, then i log msgs and i do open and read/write some other files too

well it happens that sometimes my shadetable when written to the hd has msgs from the logfile, and it sometimes accesses my textures with writing mode enabled..

everytime i log a msg i open log.txt and close, so there should be no problem.. i dunno whats happening
any ideas ?
If your overwriting your textures, its very possible you have something that is trashing your filename.
the problem continues.
i create log.txt (write mode), and then i load my textures (read mode)
if i happen to log any info during the texture load it writes that info the current texture being loaded..

the pointer to log.txt changes to the last file being opened, in this case a texture..

its pretty weird.. even on the PC version it happens

my log.txt is created with fopen/fwrite
the textures i load with winapi funcs CreateFile/ReadFile

i dont understand its confusion..

cant i have different files opened and be able to write to one and read from another?
i have it working on other projects.. its the same Logfile class, but here it messes up..
hmm i still dont get it..
Why not just use CreateFile for your log file as well? Since you are using it already I see no reason to additionally create dependencies with the standard C libs. But you may be using them elsewhere heavily so it might not matter. (Or vice versa and use fopen with your textures.)

Anyway there is a limit to the number of open file handles you can have but it should at least be 16, like 256 or more. Try to compare (view in a debugger) the file handle returned from each function and see if they differ initially, that should tell wether the functions are messing it up or its on your end.

Try to include some code next time, since if there is an error in your code there is no way for anyone to spot it.
Code:

class CFile
{
public:
// Enum access modes
enum ACCESSMODE
{
WRITE = 0,
READ = 1
};


CFile();
~CFile();

BOOL Open( NCHAR *pFilename, ACCESSMODE mode = READ );
BOOL Close();

void Read( void *lpBuffer, DWORD dwNumBytesToRead );
void Write( void *lpBuffer, DWORD dwNumBytesToWrite );

//HANDLE GetHandle() { return m_Handle; }

private:
// File handle
static HANDLE m_Handle;

// Number of bytes read
DWORD m_BytesRead;

// Number of bytes written
DWORD m_BytesWritten;

};


that is my file handling class.
i used this class to open my textures for reading/writing.
well i fixed my problem.. i just removed this class and wrote it in the texture loading function itself.
its fixed!! now i ask.. why it didnt work with the CFile class??
i did called Close everytime i called a Open. i did few tests to see if it didnt return any error. it was ok! i still cant explain why my logger would write to the last file opened with this class.
how would 2 objects mess up its pointers ? or overwrite addresses of last opened file..

im sure this is something about c++ coding that im not aware of, if anyone has a possible idea, id appreciate
I'm not positive about this, but I would say that you shouldn't be using any static variables in a class unless they are class-wide like a window procedure for a window class. A real programmer like Dan or someone will have to confirm that though.
Right, you don't want all instances of the class to have the same value for m_Handle, so it shouldn't be static. Just remove the static and it should work.

Dan East
im sorry that static there was wrong, i actually have the handle non-static and still the problem continues. its not about being static or not im afraid
it actually was targetted to the LogFileName member. anyway after reusing commented code, it all works out perfectly now. go figure! thanks