Jump to content
  • Advertisement
Sign in to follow this  
choffstein

CFBundle

This topic is 4773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is such a huge stretch, considering it is a Mac thing, but I am having trouble loading bundles. Here is my code:
#include <iostream>
#include <CoreFoundation/CoreFoundation.h>

using namespace std;

typedef void (*voidFuncPtr)();

void MyLoadPrivateFrameworkBundle (CFStringRef framework, 
                                CFBundleRef *bundlePtr)               
// 1
{
    CFURLRef    baseURL     = NULL;
    CFURLRef    bundleURL   = NULL;

    CFBundleRef myAppsBundle= NULL;
	
    if ( bundlePtr == NULL ) goto Bail;

    *bundlePtr = NULL;
    
	cout << "Getting main Bundle." << endl;
	myAppsBundle= CFBundleGetMainBundle();                              
	if ( myAppsBundle == NULL ) goto Bail;
    
	cout << "CopyPrivateFrameworksURL" << endl;
	baseURL = CFBundleCopyPrivateFrameworksURL (myAppsBundle);          
    if ( baseURL == NULL ) goto Bail;
	
	cout << "CreateCopyAppendingPathComponent." << endl;
    bundleURL = CFURLCreateCopyAppendingPathComponent (
                                kCFAllocatorSystemDefault, 
								baseURL,
                                framework,
                                false );   
	if ( bundleURL == NULL ) goto Bail;
	
	/*
	cout << "Get URL" << endl;
	bundleURL = CFURLCreateWithFileSystemPath(
                kCFAllocatorDefault, 
                CFSTR("BundleTest.bundle"),
                kCFURLPOSIXPathStyle,
                true );
	*/
	
	cout << "BundleCreate" << endl;
    *bundlePtr = CFBundleCreate (NULL, bundleURL);                     
	if ( *bundlePtr == NULL ) goto Bail;

	cout <<"Load executable." << endl;
	if ( ! CFBundleLoadExecutable (*bundlePtr) )                        
	{
		cout << "Failed to load executable." << endl;
		CFRelease (*bundlePtr);
		*bundlePtr = NULL;
	}

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

int main()
{
    CFBundleRef myCFBundle;
	voidFuncPtr print = NULL; // pointer to the print() function in the shared lib
	
	MyLoadPrivateFrameworkBundle(CFSTR("BundleTest.bundle"), &myCFBundle);
	
	if(myCFBundle)
	{
		print = (voidFuncPtr) CFBundleGetFunctionPointerForName(myCFBundle, CFSTR("print"));
	
		if(print != NULL)
			print();
	}
	else
	{
		cout << "myCFBundle failed to load." << endl;
	}
	
	if(myCFBundle) CFRelease(myCFBundle);
		
	return 1;
}


I built it in XCode as a standard C++ tool that loads the Core Foundation framework so I can use CFBundle -- except it always fails at CreateBundle(). I have my bundle, "BundleTest.bundle" sitting in the application directory, so I know its there -- maybe it has something to do with how I created the bundle? So that is my question right now: how do I go about correctly creating a bundle? I have three options in XCode: CFPlugIn, Cocoa Bundle, and Carbon Bundle. The XCode info says that CFPlugIn is a Core Foundation Bundle, and it creates a .bundle -- but I would assume it is actually a CFPlugIn based on its name, which means I have to load it like a CFPlugIn, right? Man, this makes my head hurt. There is 0 good documentation on just creating a CFBundle. If I figure this out, I am so writing a tutorial.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!