can I pass an object from cpp to c

J

jamy

Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.
 
M

Michel Bardiaux

jamy said:
Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.
Route #1: define the 'thing' as a C struct instead of a C++ class. This
is of course possible only if you have control of the C++ code.

Route #2: in the C++ source export an API callable from C in which each
C++ object will be represented by a handle, and there will be functions
(1 by result type for get, maybe 1 for set) to access the members;
either 1 (or more) per member, of generic ones with the member name
given as a string.

HaND,
--
Michel Bardiaux
R&D Director
T +32 [0] 2 790 29 41
F +32 [0] 2 790 29 02
E mailto:[email protected]

Mediaxim NV/SA
Vorstlaan 191 Boulevard du Souverain
Brussel 1160 Bruxelles
http://www.mediaxim.com/
 
K

Kenny McCormack

Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.

Not portable. Can't discuss it here. Blah, blah, blah.

To be just a little more verbose: The C standard says nothing about
interfacing with any other language.
 
R

Richard Heathfield

jamy said:
Hi all,
I have a piece of code written in c++. I wanted to pass that
object to a Cprogram. Can I do that, then how can I access the members
of that object from C function.

You can certainly pass objects from C++ programs to C functions, although
the mechanism for so doing is a C++ mechanism and so discussion of it ought
really to be taken up in the comp.lang.c++ newsgroup.

To pass an object from a C++ program to a C /program/ is also possible, but
the mechanism for doing so (other than writing the data out to a file and
then reading that file from the C program, which is portable but clumsy)
would involve inter-process communication mechanisms that are beyond the
scope of either comp.lang.c or its C++ sister newsgroup. If this is what
you actually meant, then I suggest you ask the question in a newsgroup
devoted to your platform - perhaps comp.unix.programmer or
comp.os.ms-windows.programmer.win32 would be appropriate.
 
J

jamy

Can u plz tell me some thing about how to export API callable from C ,
and how to represent each object as a handle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top