• 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
C++ pointer to Cocoa object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

C++ pointer to Cocoa object


  • Subject: C++ pointer to Cocoa object
  • From: Casey McDermott <email@hidden>
  • Date: Fri, 07 Sep 2018 17:46:43 +0000 (UTC)

We need to link some of our C++ classes to a matching Cocoa class.
It's easy for Cocoa to reference C++ objects.  Going the other way is harder.

We have been using a linker class that has a void pointer to the Obj-C object
in the C++ header.  We then cast it to a Cocoa object in the Obj-C++ source.
For example, in the C++ header we have:

void *mCocoaPopupPtr = nil;

Then in the source:

void GSCocoaPopupLinker::setCocoaFieldVisible(const BOOL inValue)
{
        if (mCocoaPopupPtr != nil)
        {
                GSPopupButton *cocoaPopup = (__bridge GSPopupButton
*)mCocoaPopupPtr;
                [cocoaPopup setHidden : !inValue];
        }
}

Problem is, with ARC turned on, the pointer is never nil, so it crashes.
The void pointer somehow becomes an NSAtom instead of 0.

There's very little documentation on NSAtom, but it appears to be Apple's way
to
use the excess bits in a 64-bit address to store class info.

Is there some other way to test for an invalid void pointer?

Thanks,

Casey McDermott
TurtleSoft.com
_______________________________________________

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

  • Follow-Ups:
    • Re: C++ pointer to Cocoa object
      • From: Jean-Daniel <email@hidden>
    • Re: C++ pointer to Cocoa object
      • From: Alex Zavatone <email@hidden>
    • Re: C++ pointer to Cocoa object
      • From: Jens Alfke <email@hidden>
    • Re: C++ pointer to Cocoa object
      • From: Saagar Jha <email@hidden>
    • Re: C++ pointer to Cocoa object
      • From: James Walker <email@hidden>
    • Re: C++ pointer to Cocoa object
      • From: Allan Odgaard <email@hidden>
  • Prev by Date: Re: Mojave Privileged Helper Tool - full disk access
  • Next by Date: Re: C++ pointer to Cocoa object
  • Previous by thread: Re: Mojave Privileged Helper Tool - full disk access
  • Next by thread: Re: C++ pointer to Cocoa object
  • Index(es):
    • Date
    • Thread