Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Loading C++ libraries via CFBundle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Loading C++ libraries via CFBundle



On 5/12/02 11:13 am, EJ Campbell <email@hidden> wrote:
> I don't believe CFBundle smoothes over the differences between two C++
> compilers. That's what I meant from ABI incompatible. But I imagine

Understood.

> this won't actually be a problem since Palm's library most likely
> defines static entry points, which means it basically has a C calling
> interface not a C++ interface. Can you show me an example of how you're
> calling into the Palm CFM library? Are you directly operating on

The API exposed by Palm is entirely defined in C, with two twists.

One is that a lot of the arguments passed to the functions are passed by
reference which is not legal in C... Apparently CW passes a pointer when a
parameter is defined to be a reference to something. That might be a bad
assumption.

Also "interesting" is that a lot of the arguments are C++ "objects" although
the documentation says they have no member functions (why aren't they just
structs then?) however my code's not calling functions that take those kind
of parameters yet so that's a challenge for the future.

(It's a really badly defined API!)

Anyway, this works:

// initialization code
#define FindFunction(f) \
CFBundleGetFunctionPointerForName(bundle,CFSTR(f))

url = CFURLCreateWithFileSystemPath(NULL,
CFSTR("/Users/cjr/Desktop/HotSync Libraries.cfm"),
kCFURLPOSIXPathStyle,
TRUE);
bundle = CFBundleCreate(url);
CFRelease(url);

// first example
long major = 0, minor = 0;
// long SyncGetAPIVersion(long *, long *)
typedef long(*syncgetvers)(long *,long *);
syncgetvers f = (syncgetvers)FindFunction("SyncGetAPIVersion");
if (f) {
ret = f(&major, &minor);
}
// major and minor now hold the expected values.

Disassembling SyncGetAPIVersion reveals it just writes two longs to the
pointers passed to it and returns. It is what a described as a "simple"
function earlier.

This doesn't work:

// second example
long handle = 0;
// long SyncRegisterConduit(long &)
typedef long (*syncregcond)(long *);
syncregcond f = (syncregcond)FindFunction("SyncRegisterConduit");
if (f) {
ret = f(&handle);
}
// ret contains an error code.

Disassembling SyncRegisterConduit reveals it wanting to call some methods on
some C++ object that's entirely internal to the Palm library, and returning
some error code because it can't.

> objects are you using standard functions? What exactly works and does
> not work? Do only calls to static objects have problems?

There are no objects (static or otherwise) in the library exposed for me to
call.

Cheers,

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

References: 
 >Re: Loading C++ libraries via CFBundle (From: EJ Campbell <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.