Using C code in symbian

Porting
in

Calling the C function in C++ file (Porting)

1.

Create a header file(.h) for your “c” program. The contents of the header file will look like

#ifdef __cplusplus
extern "C" {
#endif

// functions that you going to call in
C++
void yourFunction( );
void PrintfMessage();
int sum ( int i,int j);
......
......
......

#ifdef __cplusplus
}
#endif

2:

Now create your related “.c“file which includes all the function's definitions which are declared in the above “.h” files. If required As well other “.c” file whose functions will be called by “.c” functions. For instance, sum( ) will call GetFirstNumber( ) that is in another “.c” file.

3:

Now You have to edit the MMP file. a) Add the filename

SOURCE <filename.c >

b) Add STDLIB's header.

SYTEMINCLUDE     \epoc32\include\libc

c) The import library estlib.lib is the C standard library.

LIBRARY          estlib.lib

4:

Call yourFunction( ); from C++ file. This C++ file should have the “.h” of the “c” file.

5:

This is only for console based, rest of the steps are same. For, Console based application (i.e., for .exe ) The project also links to ecrt0.lib. This file provides the E32Main() entrypoint for a “.exe”

STATICLIBRARY   ecrt0.lib


> Using C code in symbian

Do socket functions (in stdlib) work?

> Using C code in symbian

should work theoretically , atleast ;-)

Using C code in symbian

Dear Sir, Can you tell me whether we have to include any Header file or write Main() in our .c file or simply we have to give the definitions only. regards Himanshu

Using C code in symbian

Dear sir, i tried what you have written in this article. i have perform the following changes in my console based program: create a header file cappliacation.h

#ifdef __cplusplus extern "C" #endif void printmessage();

#ifdef __cplusplus #endif

created a .c file capplication.c

void printmessage() printf(" %s ","hellohellos");

my .mmp file is as follows

// HelloWorld.mmp TARGET HelloWorld.exe TARGETTYPE exe UID 0 SOURCEPATH . SOURCE HelloWorld.cpp SOURCE capplication.c

USERINCLUDE . USERINCLUDE ..\CommonFramework SYSTEMINCLUDE \Epoc32\include LIBRARY euser.lib LIBRARY estlib.lib STATICLIBRARY ecrt0.lib

i am calling the function printmessage() in cpp file as follows

#include "CommonFramework.h" #include "capplication.h" // do the example LOCAL_C void doExampleL() _LIT(KHelloWorldText,"Hello world!\n"); console->Printf(KHelloWorldText); //char *s = (char*)0x8000000l;

printmessage();

// *s='f';

code gets compile & runs but i am not able to see the output "hellohellos" on my mobile screen. waiting for your reply. regards Himanshu

Using C code in symbian

Dear sir, i tried what you have written in this article. i have perform the following changes in my console based program: create a header file cappliacation.h

#ifdef __cplusplus

extern "C"

#endif void printmessage();

#ifdef __cplusplus

#endif

created a .c file capplication.c

void printmessage()

printf(" %s ","hellohellos");

my .mmp file is as follows

// HelloWorld.mmp

TARGET HelloWorld.exe

TARGETTYPE exe

UID 0

SOURCEPATH .

SOURCE HelloWorld.cpp

SOURCE capplication.c

USERINCLUDE .

USERINCLUDE ..\CommonFramework

SYSTEMINCLUDE \Epoc32\include

LIBRARY euser.lib

LIBRARY estlib.lib

STATICLIBRARY ecrt0.lib

i am calling the function printmessage() in cpp file as follows

#include "CommonFramework.h"

#include "capplication.h"

// do the example

LOCAL_C void doExampleL()

_LIT(KHelloWorldText,"Hello world!\n");

console->Printf(KHelloWorldText);

//char *s = (char*)0x8000000l;

printmessage();

// *s='f';

code gets compile & runs but i am not able to see the output "hellohellos" on my mobile screen.

waiting for your reply.

regards

Himanshu

suggession

My suggession is that which we are going to explain it should be clear step by step
sorry Dont mind this is a suggession only
please excuse me
Lucky