Example using E32Main()

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);
    if (fwrite(buf, sizeof(char), strlen(buf), fd) < 0 )
        perror("write fails.");

GLDEF_C TInt E32Main()
    CTrapCleanup* cleanup=CTrapCleanup::New();
    delete cleanup; // destroy cleanup stack
    return 0; // and return