Symbian3/SDK/Source/GUID-788031A5-75C1-420E-9E2B-71E09FF08ADF.dita
changeset 0 89d6a7a84779
equal deleted inserted replaced
-1:000000000000 0:89d6a7a84779
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-788031A5-75C1-420E-9E2B-71E09FF08ADF" xml:lang="en"><title>Example
       
    13 using <codeph>E32Main()</codeph></title><shortdesc/><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>A simple example using <codeph>E32Main()</codeph> as an entry point is
       
    15 described below. The example writes a text to a file. </p>
       
    16 <ul>
       
    17 <li><p>Modify the MMP file as mentioned earlier.</p></li>
       
    18 <li><p>Create a trap handler using <xref href="GUID-17AC7BAD-1C03-3729-BCC6-F5B28B32E99D.dita"><apiname>CTrapCleanup</apiname></xref>.</p></li>
       
    19 <li><p>Call the method within <codeph>TRAPD</codeph>.</p></li>
       
    20 <li><p>Delete the trap handler. </p></li>
       
    21 </ul>
       
    22 <codeblock xml:space="preserve">#include &lt;stdio.h&gt;
       
    23 #include &lt;string.h&gt;
       
    24 #include &lt;e32base.h&gt;
       
    25 
       
    26 void doExampleL(void)
       
    27 {
       
    28     FILE* fd;
       
    29     char* fileName = "C:\\test.txt";
       
    30     char *buf = "Hello world from E32Main()";
       
    31     fd = fopen(fileName, "w");
       
    32     if (fd == NULL)
       
    33     {
       
    34         printf("Unable to open the file (%s)", fileName);
       
    35         return;
       
    36     }
       
    37     if (fwrite(buf, sizeof(char), strlen(buf), fd) &lt; 0 )
       
    38     {
       
    39         perror("write fails.");
       
    40     }
       
    41     fclose(fd);
       
    42 }
       
    43 
       
    44 GLDEF_C TInt E32Main()
       
    45     {
       
    46     CTrapCleanup* cleanup=CTrapCleanup::New();
       
    47     TRAPD(error,doExampleL());
       
    48     delete cleanup; // destroy cleanup stack
       
    49     return 0; // and return
       
    50     }
       
    51 </codeblock>
       
    52 </conbody></concept>