can I pass an object from cpp to c

Discussion in 'C Programming' started by jamy, Dec 19, 2005.

  1. jamy

    jamy Guest

    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.
     
    jamy, Dec 19, 2005
    #1
    1. Advertising

  2. 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:

    Mediaxim NV/SA
    Vorstlaan 191 Boulevard du Souverain
    Brussel 1160 Bruxelles
    http://www.mediaxim.com/
     
    Michel Bardiaux, Dec 19, 2005
    #2
    1. Advertising

  3. In article <>,
    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.
     
    Kenny McCormack, Dec 19, 2005
    #3
  4. 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)
     
    Richard Heathfield, Dec 19, 2005
    #4
  5. jamy

    jamy Guest

    Can u plz tell me some thing about how to export API callable from C ,
    and how to represent each object as a handle
     
    jamy, Dec 22, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DrUg13
    Replies:
    1
    Views:
    487
    DrUg13
    Feb 10, 2004
  2. jr
    Replies:
    2
    Views:
    2,189
    John Harrison
    May 12, 2004
  3. Alex Vinokur
    Replies:
    7
    Views:
    416
    Greg Comeau
    Nov 15, 2004
  4. Vinu
    Replies:
    9
    Views:
    643
  5. www.hitechskill.com
    Replies:
    0
    Views:
    1,369
    www.hitechskill.com
    Apr 9, 2006
Loading...

Share This Page