A simple example using E32Main() as an entry point is described below. The example writes a text to a file.
Modify the MMP file as mentioned earlier.
Create a trap handler using CTrapCleanup.
Call the method within TRAPD.
Delete the trap handler.
#include <stdio.h> #include <string.h> #include <e32base.h> void doExampleL(void) { FILE* fd; char* fileName = "C:\\test.txt"; char *buf = "Hello world from E32Main()"; fd = fopen(fileName, "w"); if (fd == NULL) { printf("Unable to open the file (%s)", fileName); return; } if (fwrite(buf, sizeof(char), strlen(buf), fd) < 0 ) { perror("write fails."); } fclose(fd); } GLDEF_C TInt E32Main() { CTrapCleanup* cleanup=CTrapCleanup::New(); TRAPD(error,doExampleL()); delete cleanup; // destroy cleanup stack return 0; // and return }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.