Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Loading embedded frameworks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading embedded frameworks



On 8/25/05 6:31 PM, Le Stang Jean-Baptiste didst favor us with:

void    LoadPrivateFrameworkBundle( CFStringRef framework,
CFBundleRef *bundlePtr ){
     CFURLRef    baseURL            = NULL;
     CFURLRef    bundleURL        = NULL;
     CFBundleRef    myAppsBundle    = NULL;
     if ( bundlePtr != NULL ){
         myAppsBundle    = CFBundleGetMainBundle();
         if ( myAppsBundle != NULL ){
             baseURL    = CFBundleCopyPrivateFrameworksURL(myAppsBundle);
             if (baseURL != NULL){
                 bundleURL =
CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL,
framework,false);
                 if (bundleURL != NULL){
                     *bundlePtr = CFBundleCreate( kCFAllocatorSystemDefault,
bundleURL );
                     if ( ! CFBundleLoadExecutable( *bundlePtr ) ){
                         CFRelease(*bundlePtr);
                         *bundlePtr    = NULL;
                     }
                 } else {
                     *bundlePtr = NULL;
                 }
             } else {
                 *bundlePtr = NULL;
             }
         } else {
             *bundlePtr = NULL;
         }
     } else {
         *bundlePtr = NULL;
     }

     if ( bundleURL != NULL )    CFRelease( bundleURL );
     if ( baseURL != NULL )        CFRelease( baseURL );
}

Two comments:

1. This seems unduly complicated. Why not:

CFBundleRef    LoadPrivateFrameworkBundle( CFStringRef framework )
{
    CFBundleRef    frameworkBundle    = NULL;
    CFURLRef    baseURL            = NULL;
    CFURLRef    bundleURL        = NULL;
    CFBundleRef    myAppsBundle    = NULL;

    myAppsBundle    = CFBundleGetMainBundle();
    if ( myAppsBundle != NULL ){
        baseURL    = CFBundleCopyPrivateFrameworksURL(myAppsBundle);
        if (baseURL != NULL){
            bundleURL =
CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault, baseURL,
framework,false);
            if (bundleURL != NULL){
                frameworkBundle = CFBundleCreate( kCFAllocatorSystemDefault,
bundleURL );
                if ( ! CFBundleLoadExecutable( frameworkBundle ) ){
                    CFRelease(frameworkBundle);
                    frameworkBundle = NULL;
                }
                CFRelease( bundleURL );
            }
            CFRelease( baseURL );
        }
    }

    return frameworkBundle;
}

2. Since CFBase.h says:
"You should rarely use kCFAllocatorSystemDefault, the default default
allocator," why are you using kCFAllocatorSystemDefault instead of
kCFAllocatorDefault?

Larry

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Loading embedded frameworks (From: Le Stang Jean-Baptiste <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.