• 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: Backwards compatibility and CFBundleGetFunctionPointerForName
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Backwards compatibility and CFBundleGetFunctionPointerForName


  • Subject: Re: Backwards compatibility and CFBundleGetFunctionPointerForName
  • From: Douglas Davidson <email@hidden>
  • Date: Wed, 12 Nov 2003 17:06:49 -0800

On Nov 12, 2003, at 4:03 PM, Todd Clements wrote:

I'm having a bit of trouble trying to ensure backwards compatibility for my application (using 10.2 features when they are available, but allowing the program to launch on 10.1). There are only a few features I'd like to use, so I had planned on just using CFBundleGetFunctionPointerForName to load function pointers and use those (this is the best information I could find on Apple's site, but it may not be the best way to do it.)

For example, if I wanted to use NSProgressIndicator's setDisplayedWhenStopped, which is 10.2 only, I tried to use the following code inside a category I made on NSProgressIndicator:

NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
void ((*myFunction)()) = CFBundleGetFunctionPointerForName((CFBundleRef)myBundle CFSTR("setDisplayedWhenStopped"));

You're making this much harder than it is, because you're confusing C and Objective-C. First of all, NSBundle and CFBundle are not toll-free bridged, so you can't just cast between them. That's the cause of your immediate problems. (There is a one-to-one correspondence between CFBundles and NSBundles, and there are a number of things that can be done with either, but you just have to create them both separately from paths or identifiers or whatever other means you use to get your bundles.)

The second problem is that CFBundleGetFunctionPointerForName() is for getting functions. Not methods, functions. For Objective-C methods, you don't have to go through all of this rigmarole. All you have to do is call respondsToSelector:, and then if it does respond, just call the method. If it doesn't respond, don't call the method. It just works.

Douglas Davidson
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Backwards compatibility and CFBundleGetFunctionPointerForName (From: Todd Clements <email@hidden>)

  • Prev by Date: Re: Mouse move event
  • Next by Date: Re: Matching Postal Addresses
  • Previous by thread: Backwards compatibility and CFBundleGetFunctionPointerForName
  • Next by thread: Cocoa daemon
  • Index(es):
    • Date
    • Thread