Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > can I pass an object from cpp to c

Reply
Thread Tools

can I pass an object from cpp to c

 
 
jamy
Guest
Posts: n/a
 
      12-19-2005
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.

 
Reply With Quote
 
 
 
 
Michel Bardiaux
Guest
Posts: n/a
 
      12-19-2005
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 private.php?do=newpm&u=

Mediaxim NV/SA
Vorstlaan 191 Boulevard du Souverain
Brussel 1160 Bruxelles
http://www.mediaxim.com/
 
Reply With Quote
 
 
 
 
Kenny McCormack
Guest
Posts: n/a
 
      12-19-2005
In article <. com>,
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.


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.

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      12-19-2005
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)
 
Reply With Quote
 
jamy
Guest
Posts: n/a
 
      12-22-2005
Can u plz tell me some thing about how to export API callable from C ,
and how to represent each object as a handle

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free online test in C, CPP / Placement papers / CPP,C Interview Questions www.hitechskill.com C++ 0 04-09-2006 10:53 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[]) Vinu C++ 9 05-05-2005 04:11 AM
Method inlined in source1.cpp and called in source2.cpp Alex Vinokur C++ 7 11-15-2004 09:14 PM
What is better /standard for creating files. a cpp file with header or cpp and seperate file for header DrUg13 C++ 1 02-10-2004 09:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57