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:

>Can XERCES-C be used in C programs, even though it is C++?  Are there C
>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

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).




#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)


in myapi.h:

#ifndef MYAPI_H_
#define MYAPI_H_

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

#ifdef __cplusplus

#endif  /* MYAPI_H_*/


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

#include <myapi.h>

int somefunction(void)
   myapi_init();  //get an object

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.


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

View raw message