• Re: How to Call Objective C Object from C++ code

    From Mopelee@kingdry_cn@sina.com.cn to comp.sys.mac.system on Friday, April 07, 2006 00:54:23
    From Newsgroup: comp.sys.mac.system

    thank u, Tom.
    I know how to call objective c from objective c++,just like call from
    .mm to .m.
    but i wanna find some way to to call from .cpp to .m
    anyone have idea?

    --- Synchronet 3.18b-Win32 NewsLink 1.113
  • From Tom Harrington@tph@pcisys.no.spam.dammit.net to comp.sys.mac.system on Friday, April 07, 2006 10:38:04
    From Newsgroup: comp.sys.mac.system

    In article <1144396463.858577.245830@e56g2000cwe.googlegroups.com>,
    "Mopelee" <kingdry_cn@sina.com.cn> wrote:

    thank u, Tom.
    I know how to call objective c from objective c++,just like call from
    .mm to .m.
    but i wanna find some way to to call from .cpp to .m
    anyone have idea?

    Normally Xcode will compile a .cpp as C++, and won't recognize
    Objective-C method calls. However for any file you can override the
    defalult and tell Xcode to treat it differently. You do this by
    selecting the file in Xcode and opening the inspector window. Under the
    "File type" setting, choose the appropriate option. From your
    description I think you'd want "sourcecode.cpp.objcpp".

    --
    Tom "Tom" Harrington
    Macaroni, Automated System Maintenance for Mac OS X.
    Version 2.0: Delocalize, Repair Permissions, lots more.
    See http://www.atomicbird.com/
    --- Synchronet 3.18b-Win32 NewsLink 1.113
  • From shamino@shamino@techie.com (David C.) to comp.sys.mac.system on Saturday, April 08, 2006 20:46:53
    From Newsgroup: comp.sys.mac.system

    "Mopelee" <kingdry_cn@sina.com.cn> writes:

    I know how to call objective c from objective c++,just like call from
    .mm to .m.
    but i wanna find some way to to call from .cpp to .m
    anyone have idea?

    Objective C is C, plus the object/method extensions.

    You can't make an Objective C method call from C++ code, but you can
    call an ordinary function. So should be able to make a simple Objective
    C source file (.m extension) containing a C function that makes the
    method call. Declare the prototype for that function (in an extern "C"
    block) in your C++ file and call it.

    At least I would expect this to work. Haven't actually tried it.

    You might prefer to ask on one of the comp.sys.mac.programmer
    newsgroups. They will probably be able to give you better answers.

    -- David
    --- Synchronet 3.18b-Win32 NewsLink 1.113
  • From Mat Cvetic@invalid@invalid.net to comp.sys.mac.system on Sunday, April 09, 2006 05:27:22
    From Newsgroup: comp.sys.mac.system

    In article <1144396463.858577.245830@e56g2000cwe.googlegroups.com>,
    "Mopelee" <kingdry_cn@sina.com.cn> wrote:

    thank u, Tom.
    I know how to call objective c from objective c++,just like call from
    .mm to .m.
    but i wanna find some way to to call from .cpp to .m
    anyone have idea?

    I think you're looking for the objc_msgSend() function. I haven't used
    it so I don't know all the ins and outs.
    --- Synchronet 3.18b-Win32 NewsLink 1.113
  • From shamino@shamino@techie.com (David C.) to comp.sys.mac.system on Sunday, April 09, 2006 16:47:04
    From Newsgroup: comp.sys.mac.system

    Mat Cvetic <invalid@invalid.net> writes:

    I think you're looking for the objc_msgSend() function. I haven't used
    it so I don't know all the ins and outs.

    Note, however, that this is not portable. From the top of the
    documentation page where it is described:

    The Mac OS X implementation of the Objective-C runtime library
    is unique to the Mac OS X platform. For other platforms, the GNU
    Compiler Collection provides a different implementation with a
    similar API. This document covers only the Mac OS X
    implementation.

    So, if you think you may need to bridge Objective C with C++ on some
    other platform (remember that gcc supports Objective C on many
    platforms), you should use the mechanism I described - writing your own Objective C function with a C interface and use that as the bridge.

    -- David
    --- Synchronet 3.18b-Win32 NewsLink 1.113