Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFPlugin loading question




On May 20, 2006, at 5:44 PM, Jack Small wrote:

There are about a half a dozen ways to do that. It depends on your target settings and other project specifics.

I would start by reading the Xcode documentation like
<file:///Developer/ADC%20Reference%20Library/documentation/MacOSX/ Conceptual/BPFrameworks/Tasks/ExportingInterfaces.html#//apple_ref/ doc/uid/20002260>


Or asking on the Xcode mailing list.

You might get away with something simple like:

#pragma export on
void MyPluginInitialize(void);
#pragma export off

You can use the nm tool in terminal on your bundle binary to see what symbols are exported.

I should also mention that CFBundleCreate can return NULL which would cause problems in your example code.

Thanks Jack.

I fumbled around the dynamic library design guidelines here: http:// developer.apple.com/documentation/DeveloperTools/Conceptual/ DynamicLibraries/Articles/DynamicLibraryDesignGuidelines.html#// apple_ref/doc/uid/TP40002013-SW17

And it turns out there are these awful looking things called "module initializers" which can also be used on applications, and as luck would have it, bundles too. Basically the module initializer is called as the bundle loads so it's possible to do any required setup in a function flagged as the initializer.

Also found something similar to mark functions for export

Here's what I came up with in case anyone else needs to load and load bundles that use Cocoa code from Carbon host applications:

// globals
static BOOL		gCocoaInitialized		= NO;

// Defines: (Purely for aesthetics)
#define EXPORT_SYMBOL __attribute__((visibility("default")))
#define LOAD_INITIALIZER __attribute__((constructor))

// Define a function as the load time initializer:
LOAD_INITIALIZER
static void DoLoadTimeInitialization()
{
	if (gCocoaInitialized == NO)
	{
		NSApplicationLoad();
		gCocoaInitialized		= YES;
	}
}

// Define a function for export
EXPORT_SYMBOL
void SayHelloInSpanish()
{
	NSLog(@"Hola");
}

EXPORT_SYMBOL
void SayHelloInEnglish()
{
	NSLog(@"Hello");
}

EXPORT_SYMBOL
void SayHelloInFrench()
{
	NSLog(@"bonjour ");
}

With an initializer defined, CFBundleGetFunctionPointerForName works as one would expect.

Ken


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

This email sent to email@hidden
References: 
 >CFPlugin loading question (From: Ken Tozier <email@hidden>)
 >Re: CFPlugin loading question (From: Ken Tozier <email@hidden>)
 >Re: CFPlugin loading question (From: Jack Small <email@hidden>)
 >Re: CFPlugin loading question (From: Ken Tozier <email@hidden>)
 >Re: CFPlugin loading question (From: Jack Small <email@hidden>)



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

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.