Calling C++ functions from C

This is a discussion on Calling C++ functions from C within the C++ Programming forums, part of the General Programming Boards category; I read the post: http://cboard.cprogramming.com/cplus...plus-code.html This shows how to call from C++ to C, but it didn't discuss how to ...

  1. #1
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72

    Calling C++ functions from C

    I read the post:
    combining c with c++ code

    This shows how to call from C++ to C, but it didn't discuss how to call from C to C++ which is what I'm really needing to do.

    Does anybody have any advice on how to do this?

    Thanks,
    Mike
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    I don't think there's a way to do it in the C code.

    Perhaps you can make a .dll and reference it?

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    [32] How to mix C and C++, C++ FAQ Lite
    It needs to start off as a C++ program, then you can wander between the two as much as you like.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72
    The C program is a server that is resident on a device. It's static and starts up when the device does. The C++ application is the open source OSS browser. It gets loaded dynamically in the device at run time (it's a DLL). Does that mean it's pretty much impossible or can I define an API in that case? If so, I've never defined an API before and might need some pointers on how to do that.

    Thanks!
    Mike
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Can't you "exec" your browser?
    Why does it need to be a DLL?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72
    Salem,
    It's all embedded code. I'm not all that certain I understand what you mean by "exec" the browser. I suspect you are suggesting that I start the browser from the C code. I cannot do that. I'd get fired!
    This device is a retail product.

    Thanks!
    Mike
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

  7. #7
    Registered User
    Join Date
    Jul 2009
    Location
    Puget Sound, WA
    Posts
    3
    Sure you won't get fired discussing it on open forums?

  8. #8
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Do you just need to call C++ stand-alone functions, or do you need to create objects and call member functions?

    Why not write some wrapper functions in C++ that call the C++ code and export those functions as extern "C" so your C program can call your wrapper functions?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  9. #9
    Registered User mlupo's Avatar
    Join Date
    Oct 2001
    Posts
    72
    Thanks cpjust. I may do just that despite having been discouraged from this approach by our architects. I'm being "encouraged" to use function pointers instead.
    FYI: As a test engineer who knows just enough C to be dangerous, I've been elected to implement some test hooks into our code. Hence, working with advanced topics in C++ all the while being a C++ noob. It's been quite a vertical learning curve.
    NEVER PET YOUR DOG WHILE IT'S ON FIRE!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  2. Replies: 9
    Last Post: 01-26-2008, 02:12 AM
  3. calling functions: exit and return
    By 911help in forum C Programming
    Replies: 3
    Last Post: 12-28-2007, 12:24 PM
  4. I Need Help Defining and Calling Functions
    By jonbuckets in forum C++ Programming
    Replies: 6
    Last Post: 10-25-2007, 09:46 AM
  5. Calling functions help
    By ForlornOdium in forum C++ Programming
    Replies: 14
    Last Post: 09-29-2003, 08:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21