• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Call Cocoa from C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Call Cocoa from C++


  • Subject: Re: Call Cocoa from C++
  • From: "Sean McBride" <email@hidden>
  • Date: Thu, 17 Dec 2009 18:00:01 -0500
  • Organization: Rogue Research Inc.

On 12/17/09 12:24 PM, Randall Meadows said:

>> How / Can I store a pointer to an obj-c object in a C++ class and then
>send messages to the obj-c object from C++?
>>
>> Somethng like:
>>
>> class MyClass
>> {
>> public:
>> 	void* objcptr; // ptr to my obj-c object
>> 	void CallOBJC(void);
>> }
>>
>> MyClass::CallOBJC()
>> {
>> 	[objcptr updateText];
>> }
>
>Just like that.  Put this into a .mm file, and it'll compile as
>Objective-C++.  You'll get a compiler warning that objcptr may not
>respond to updateText, which you can eliminate by casting objcptr to the
>appropriate class.

If you are using Cocoa Garbage Collection, be very careful doing this.
IIRC, you loose the automatic 'strongness' and will probably have to add
__strong or CFRetain/CFRelease appropriately.

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Call Cocoa from C++ (From: David Blanton <email@hidden>)
 >Re: Call Cocoa from C++ (From: Randall Meadows <email@hidden>)

  • Prev by Date: Re: narraycontroller sort performance problems
  • Next by Date: Re: App works when launched from Xcode, not from Finder
  • Previous by thread: Re: Call Cocoa from C++
  • Next by thread: Re: Call Cocoa from C++
  • Index(es):
    • Date
    • Thread