Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Forums:

Please help me.

I've created a file in phone, the size is one byte. I'm trying to read the file but I could not get any data.

my code:
===================================================
boolean File_READING(IShell *m_pIShell, char *fileName, char *data)
{
IFileMgr * m_pIFileMgr;
IFile * m_pIFile;
//OpenFileMode mode = _OFM_CREATE | _OFM_APPEND;
OpenFileMode mode = _OFM_READ;

int rc;

ISHELL_CreateInstance(m_pIShell, AEECLSID_FILEMGR,(void **) &m_pIFileMgr);

if (IFILEMGR_Test(m_pIFileMgr, fileName) == SUCCESS)
{
// Open the file for reading
if (m_pIFile = IFILEMGR_OpenFile(m_pIFileMgr, fileName, mode))
{
if((rc = IFILE_Seek(m_pIFile, _SEEK_START, 0)) != SUCCESS)
{
DBGPRINTF("IFILE_Seek() failed!!!");
return FALSE;
}

// for reading
rc = IFILE_Read(m_pIFile, data, 1);
if (rc > 0)
{
DBGPRINTF("File read succeded!!!, <%d> byte read.", rc);
}
else
{
DBGPRINTF("File read failed!!!");
IFILE_Release(m_pIFile);
m_pIFile = NULL;
IFILEMGR_Release(m_pIFileMgr);
m_pIFileMgr = NULL;
return FALSE; // read failed
}
}
// Close the file
IFILE_Release(m_pIFile);
m_pIFile = NULL;
IFILEMGR_Release(m_pIFileMgr);
m_pIFileMgr = NULL;
}
return TRUE;

=========================================
Please help me on this.

Thansk.

Did you tried with removing this code.
if((rc = IFILE_Seek(m_pIFile, _SEEK_START, 0)) != SUCCESS)
{
DBGPRINTF("IFILE_Seek() failed!!!");
return FALSE;

Did you tried with removing this code.
if((rc = IFILE_Seek(m_pIFile, _SEEK_START, 0)) != SUCCESS)
{
DBGPRINTF("IFILE_Seek() failed!!!");
return FALSE;

skumar_rao wrote:Did you tried with removing this code.
if((rc = IFILE_Seek(m_pIFile, _SEEK_START, 0)) != SUCCESS)
{
DBGPRINTF("IFILE_Seek() failed!!!");
return FALSE;

Yes, I tried without that part.
File is in current directory and writing is ok.
Reading is not working.
Thanks.

skumar_rao wrote:Did you tried with removing this code.
if((rc = IFILE_Seek(m_pIFile, _SEEK_START, 0)) != SUCCESS)
{
DBGPRINTF("IFILE_Seek() failed!!!");
return FALSE;

Yes, I tried without that part.
File is in current directory and writing is ok.
Reading is not working.
Thanks.

Hi All,
I am having this problem with the IFile_write operation... It says
"Unhandled exception at 0x00444539 in BREW_Emulator.exe: 0xC0000005: Access violation reading location 0x752e6471."
I have set the previlges in the MIF editor already but it does not work... When i try to open the file using _OFM_CREATE it gives me the same error... but for other _OFM_ types it works fine... Any one having a clue?
Regards,
Sudha

Hi All,
I am having this problem with the IFile_write operation... It says
"Unhandled exception at 0x00444539 in BREW_Emulator.exe: 0xC0000005: Access violation reading location 0x752e6471."
I have set the previlges in the MIF editor already but it does not work... When i try to open the file using _OFM_CREATE it gives me the same error... but for other _OFM_ types it works fine... Any one having a clue?
Regards,
Sudha

Create/Write/Read file is rather straight forward. Please post your code, so that forum members can provide comments.

Create/Write/Read file is rather straight forward. Please post your code, so that forum members can provide comments.

did you create the IFileMgr etc

did you create the IFileMgr etc

This is the code, it is also taken from an example... I am getting the error on using _OFM_CREATE as well when I go to the project directory on my PC and create the log.txt file manually I start getting the same error at line :IFILE_Write(pIFile, timestamp, STRLEN(timestamp));
void LogToFile(CobjTCMEDAPP * pApp, const char * const buf)
{
if (ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_FILEMGR, (void**)(&pApp->m_IFileMgr)) == SUCCESS)
{
IFile * pIFile;
if (IFILEMGR_Test(pApp->m_IFileMgr, LOGFILE) != SUCCESS)
pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_CREATE);
else
pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_APPEND);
if (pIFile != NULL)
{
JulianType jt;
char timestamp[30];
GETJULIANDATE(GETTIMESECONDS(), &jt);
SPRINTF(timestamp, "[%02d:%02d:%02d] ", jt.wHour, jt.wMinute, jt.wSecond);
IFILE_Write(pIFile, timestamp, STRLEN(timestamp));
IFILE_Write(pIFile, buf, STRLEN(buf));
IFILE_Write(pIFile, "\r\n", 2);
IFILE_Release(pIFile);
}
IFILEMGR_Release(pApp->m_IFileMgr);
}

Thanks,
Sudha

This is the code, it is also taken from an example... I am getting the error on using _OFM_CREATE as well when I go to the project directory on my PC and create the log.txt file manually I start getting the same error at line :IFILE_Write(pIFile, timestamp, STRLEN(timestamp));
void LogToFile(CobjTCMEDAPP * pApp, const char * const buf)
{
if (ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_FILEMGR, (void**)(&pApp->m_IFileMgr)) == SUCCESS)
{
IFile * pIFile;
if (IFILEMGR_Test(pApp->m_IFileMgr, LOGFILE) != SUCCESS)
pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_CREATE);
else
pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_APPEND);
if (pIFile != NULL)
{
JulianType jt;
char timestamp[30];
GETJULIANDATE(GETTIMESECONDS(), &jt);
SPRINTF(timestamp, "[%02d:%02d:%02d] ", jt.wHour, jt.wMinute, jt.wSecond);
IFILE_Write(pIFile, timestamp, STRLEN(timestamp));
IFILE_Write(pIFile, buf, STRLEN(buf));
IFILE_Write(pIFile, "\r\n", 2);
IFILE_Release(pIFile);
}
IFILEMGR_Release(pApp->m_IFileMgr);
}

Thanks,
Sudha

worked fine for me, the only problem i noticed was that i added to an existing app of mine that uses ifilemgr and it crashed later on because i use a test to see if ifilemgr is null and if so recreate it, so i added a
pApp->m_IFileMgr = NULL ;
at the end to make it work in my framework, however it crashed in a similar way you described so its possibly related, are you using IFileMgr elsewhere?

worked fine for me, the only problem i noticed was that i added to an existing app of mine that uses ifilemgr and it crashed later on because i use a test to see if ifilemgr is null and if so recreate it, so i added a
pApp->m_IFileMgr = NULL ;
at the end to make it work in my framework, however it crashed in a similar way you described so its possibly related, are you using IFileMgr elsewhere?

I am not using pApp->m_IFileMgr anywhere else... I added pApp->m_IFileMgr = NULL ; to the end as well... it does not still work... maybe it has go tsomething to do with the previliges... Even though I have given all previliges to the application excluding TAPI, Web Access and Position Location. I have set the max files to 10 and the max space to 20480... still it does not work :(
Is there something wrong the way I am calling this function i.e.
LogToFile(pApp, pApp->m_pszRpl);

I am not using pApp->m_IFileMgr anywhere else... I added pApp->m_IFileMgr = NULL ; to the end as well... it does not still work... maybe it has go tsomething to do with the previliges... Even though I have given all previliges to the application excluding TAPI, Web Access and Position Location. I have set the max files to 10 and the max space to 20480... still it does not work :(
Is there something wrong the way I am calling this function i.e.
LogToFile(pApp, pApp->m_pszRpl);

show the definition of the second parameter
just do "TEST" instead see if it works, that'll rule it out
the NULL thing would only make a difference if you were checking it and using it elsewhere, but otherwise i tried it verbatim in the 2.1 emulator.
should only need file privs.
i ran it a few times, and it was fine

show the definition of the second parameter
just do "TEST" instead see if it works, that'll rule it out
the NULL thing would only make a difference if you were checking it and using it elsewhere, but otherwise i tried it verbatim in the 2.1 emulator.
should only need file privs.
i ran it a few times, and it was fine

char * m_pszRpl;
Then I read from the socket into it saying:
nRead = ISOCKET_Read(pApp->m_pISocket, ((byte *)pApp->m_pszRpl) + pApp->m_nTCPIdx, pApp->m_nDataLength - pApp->m_nTCPIdx);
and then I try to write it in the file with the method giving error...
Can there be by any means a chance that the the emulator uses windows file management and it does not allow to write anything in this folder... manually I can do that though?

char * m_pszRpl;
Then I read from the socket into it saying:
nRead = ISOCKET_Read(pApp->m_pISocket, ((byte *)pApp->m_pszRpl) + pApp->m_nTCPIdx, pApp->m_nDataLength - pApp->m_nTCPIdx);
and then I try to write it in the file with the method giving error...
Can there be by any means a chance that the the emulator uses windows file management and it does not allow to write anything in this folder... manually I can do that though?

do you allocate a buffer for pszRpl
did you try replace the log call with just a "TEST" as the second parameter

do you allocate a buffer for pszRpl
did you try replace the log call with just a "TEST" as the second parameter

Yes, I did allocate a buffer for this variable and again it did not work with the "TEST" string either...

Yes, I did allocate a buffer for this variable and again it did not work with the "TEST" string either...

not sure then, since it works for me in the 2.1 emulator no problem
you'll probably have to provide a complete test app ,src/mif/project for much more help

not sure then, since it works for me in the 2.1 emulator no problem
you'll probably have to provide a complete test app ,src/mif/project for much more help

I have sent you a mail with the source and project with MIF file...

I have sent you a mail with the source and project with MIF file...

the prototype at the start of the code is wrong
the pApp is missing
void LogToFile(const char * const buf);
void LogToFile(CobjTCMEDAPP * pApp, const char * const buf)
pApp->m_blockinMode==FALSE;
should be
pApp->m_blockinMode=FALSE;

the prototype at the start of the code is wrong
the pApp is missing
void LogToFile(const char * const buf);
void LogToFile(CobjTCMEDAPP * pApp, const char * const buf)
pApp->m_blockinMode==FALSE;
should be
pApp->m_blockinMode=FALSE;

Thanks a lot Charlie, I have done those two changes as well but they just removed warnings... the initial issue stay there, I think I will have to rewrite the whole app again.. let us see... I will update you whatever comes up...

Thanks a lot Charlie, I have done those two changes as well but they just removed warnings... the initial issue stay there, I think I will have to rewrite the whole app again.. let us see... I will update you whatever comes up...

it worked when i did those changes, no crashes, check if append mode needs readwrite added

it worked when i did those changes, no crashes, check if append mode needs readwrite added

pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_APPEND | _OFM_READWRITE);
tested it with this and with
pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_READWRITE);
both. Did you try it with create after removing the file?

pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_APPEND | _OFM_READWRITE);
tested it with this and with
pIFile = IFILEMGR_OpenFile(pApp->m_IFileMgr, LOGFILE, _OFM_READWRITE);
both. Did you try it with create after removing the file?

Ok, I have succesfully created and written to the file... all I did was to remove the max files and max size in my MIF file... does it make sense?

Ok, I have succesfully created and written to the file... all I did was to remove the max files and max size in my MIF file... does it make sense?

yep it does, if i remember correctly the earlier simulators had problems with those settings,.

yep it does, if i remember correctly the earlier simulators had problems with those settings,.

hmm... well then it is ok... Now i have another problem regarding the synchronization of the recieved data from the socket... is there any other thread where I shall post my question ?

hmm... well then it is ok... Now i have another problem regarding the synchronization of the recieved data from the socket... is there any other thread where I shall post my question ?

i'd just start a new thread.

i'd just start a new thread.