error in opening a file!!!!!!!!!!!!!!!!!!
| Tue, 2007-11-20 08:17 | |
|
Hi, The following code crashes at run time while opening file in .h file in .cpp file TFileName fileName(KPhoneRootPath); RFs afs; ALSO TRIED WITH |
|
| Tue, 2007-11-20 08:17 | |
|
Hi, The following code crashes at run time while opening file in .h file in .cpp file TFileName fileName(KPhoneRootPath); RFs afs; ALSO TRIED WITH |
|
Forum posts: 14
Why are you pushing iFile onto the CleanupStack??
Forum posts: 159
What does R mean in Symbian's naming scheme?
What happens when you don't understand C or C++ and try and use object pointers that don't point to anything?
Forum posts: 37
I think the program crashes before reaching the CleanupClosePushL();
Can you brief "object pointers that don't point to anything".
May be I am wrong..
But I dont understand how.
Can you be breif.
I think RFile-> OPen() should have initialised.
Forum posts: 114
Hi,
Instead of using a RFile pointer "*iFile", try using RFile object "iFile".
Also there is no need to push the R class object on the clean up stack.
Chao,
Raghav
Forum posts: 1241
I don't think that's true. Depending on how the code continues after the file open (we do not see that) there would be no other way than using the cleanup stack to make sure that the file will be closed if a Leave occurs.
After all, that's why CleanupClosePushL exists.
Or did I misunderstand your post?
René Brunner
Forum posts: 114
Hi Rene,
You are right. It was my mistake. Thanks for correcting.
Chao,
Raghav
Forum posts: 14
Let's clarify something, R class objects should be pushed onto the cleanup stack but in this case RFile is an instance variable so it shouldn't be placed on cleanup stack.
Forum posts: 159
Lets clarify evern further, there is only a need to push R class objects (or C objects) onto the cleanup stack provided they aren't member variables and provided the code which follows their opening may leave - many people do this sorth of thing (not just with R objects)
RSomething x;
x.Open();
CleanupClosePushL(x);
some code with can't leave
CleanupStack::PopAndDestory(x);
Forum posts: 37
ok!
I still have some confusions...
What is the difference between these 3 approaches.I think all of them are the same .Are there any differences??????
APPROACH 1:
-----------------------
RFile iFile1;
iFile1.Open(afs,fileName,EFileShareExclusive|EFileWrite);
APPROACH 2:
-----------------------
RFile* iFile2;
(*iFile2).Open(afs,fileName,EFileShareExclusive|EFileWrite);
APPROACH 3:
-----------------------
RFile* iFile3;
iFile3->Open(afs,fileName,EFileShareExclusive|EFileWrite);
AND ONE MORE THING THAT I NEED TO CLEAR UP IS:_
-I dont need to push the iFile object because it is a member of the class.
-But still pushing them into the cleanupstack should in my opinion be an additional security step.Should that be an error?
-Moreover all the pointer variables which are members of a class are pushed into the cleanupStack. R classes are also handles to other objects.handles are somewhat similar to pointers.Then why not push it?
Regards!
Forum posts: 37
I started another helloworld program and copied the lines of code into the ConstructL() of appui.
in appui.h file
----------------
RFile* iFile;
in appui.cpp file
------------------
#define KDirPictures PathInfo::ImagesPath()
#define KPhoneRootPath PathInfo::PhoneMemoryRootPath()
_LIT (KFileName2,"Snaps.jpg");
TFileName fileName(KPhoneRootPath);
fileName.Append(KDirPictures);
fileName.Append(KFileName2);
RFs afs;
User::LeaveIfError(afs.Connect());
CleanupClosePushL(afs);
_LIT(KCameraStart,"asdasd");
CConsoleBase* gConsole;
gConsole=Console::NewL(KCameraStart,TSize(40,40));
CleanupStack::PushL(gConsole);
gConsole->ClearScreen();
gConsole->Printf(KCameraStart);
gConsole->Getch();
CleanupStack::PopAndDestroy(gConsole);
TInt err2=iFile->Open(afs,fileName,EFileShareExclusive|EFileWrite);
I ran the application in the emulator and the application:-
1.printed to the console
2.then crashed with "KERN-EXEC3"
Then I made following changes:-
in appui.h file
----------------
made
RFile* iFile to
RFile iFile
in .cpp file
-------------
made
TInt err2=iFile->Open(afs,fileName,EFileShareExclusive|EFileWrite);
as
TInt err2=iFile.Open(afs,fileName,EFileShareExclusive|EFileWrite);
I ran the application in the emulator and the application:-
1.printed to the console
2.then crashed with "E32-USER Cbase71"
Forum posts: 37
Sorry,
The code works for
Approach 1
but
not for approach 2 and 3
May I know what is the difference between 3 approaches, I thought them to be simmilar
Thanks a lot.
Forum posts: 114
Hi,
If you are using pointers the memory pointed by them should be valid. In your case you have to instantiate the RFile type
Chao,
Raghav
Forum posts: 159
Trying to learn SYmbian before learning C++ is going to be difficult for you.
In approach 2 and 3 you have not created an object, you have only created a pointer to an object.
Forum posts: 37
Thanks,
It is not that difficult till the forum is there and the responses I get.
What else can be better than learning from all the peoples on this and other forums...
"peoples" include you too.
I am thankfull..............
Whatever may be the result, I wont leave trying
Regards!