xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Jamison <rjami...@lincom-asg.com>
Subject Re: XERCES-C in C programs
Date Wed, 05 Sep 2001 13:27:43 GMT
Jason Jesso wrote:

>Hi:
>
>Can XERCES-C be used in C programs, even though it is C++?  Are there C
>bindings?
>
>Thanks
>Jason
>
>
>
>---------------------------------------------------------------------
>In case of troubles, e-mail:     webmaster@xml.apache.org
>To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
>For additional commands, e-mail: general-help@xml.apache.org
>
>
Jason,

A common way to use C++ libraries is to supply your own C API
functions in a C++ file, declare them extern "C" in the .cpp file,
and provide a .h file which lists only the function prototypes in C
form (no C++ includes).


 example:

==============

myapi.cpp:

#include <some_cpp_files>
#include "myapi.h"

static SomeClass *myobj;

extern "C" int myapi_init(void)
{
   myobj= new SomeClass();
}

extern "C" int another_wrapper_function(void)
{
   myobj->someMethod();
}

==============

in myapi.h:


#ifndef MYAPI_H_
#define MYAPI_H_

#ifdef __cplusplus
extern "C" {
#endif
int myapi_init(void);
int another_wrapper_function(void);

#ifdef __cplusplus
}
#endif

#endif  /* MYAPI_H_*/


==============

...and in the .c files that use this:

#include <myapi.h>


int somefunction(void)
{
   myapi_init();  //get an object
   another_wrapper_function();  
   ...etc...
}




Basically, what you would do in the API file, is declare a
static global object pointer, and all of the other wrapper
functions call methods on that object.

Hope this helps.




Bob



---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message