By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

can I pass an object from cpp to c

P: n/a
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.

Dec 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
jamy wrote:
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:mb*******@mediaxim.be

Mediaxim NV/SA
Vorstlaan 191 Boulevard du Souverain
Brussel 1160 Bruxelles
http://www.mediaxim.com/
Dec 19 '05 #2

P: n/a
In article <11*********************@f14g2000cwb.googlegroups. com>,
jamy <pk****@gmail.com> wrote:
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.

Dec 19 '05 #3

P: n/a
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 19 '05 #4

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

Dec 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.