10 messages in net.java.dev.jna.usersRe: [jna-users] Accessing static Obje...
FromSent OnAttachments
James WayNov 6, 2007 8:00 am 
Timothy WallNov 13, 2007 1:00 pm 
Wayne MeissnerNov 13, 2007 3:48 pm 
Duncan McGregorNov 13, 2007 4:10 pm 
Timothy WallNov 14, 2007 5:34 am 
Timothy WallNov 14, 2007 5:58 am 
Timothy WallNov 14, 2007 11:23 am 
Duncan McGregorNov 14, 2007 12:49 pm 
Shawn EricksonNov 14, 2007 1:13 pm 
Wayne MeissnerNov 26, 2007 8:15 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] Accessing static Objective-C from JNAActions...
From:Shawn Erickson (shaw@gmail.com)
Date:Nov 14, 2007 1:13:00 pm
List:net.java.dev.jna.users

On 11/14/07, Duncan McGregor <dun@oneeyedmen.com> wrote:

Thank you Timothy, Greg and Mike.

I had found the C interface to Objective-C (There's a tentative wrapper at the end of this mail).

My problem was that in order to call Objective-C methods I need to call NSSelectorFromString (a C function). This takes an NSString. In order to get an NSString from a char* (and hence easy JNA marshalling) I wanted to call the static method NSString::stringWithUTF8String:(const char *), the problem being that in order to call this static method I needed a selector, which meant calling NSSelectorFromString, which needs an NSString... So I was kind of hoping there was some short-cut to calling a static method, maybe in the way that you can call C++ functions from C if you can predict the name mangling.

Our real Cocoa hackers pointed out that CFString is compatible with NSString and can be built with the plain C function CFStringCreateWithCString, breaking the cycle and letting me get selectors for other purposes.

Note you have to CFRelease the string created from CFStringCreateXxxx.

Consider dropping down to the objc runtime API for this type of stuff.

SEL selector = sel_getUid("someMessage:a:b:c")

..of course then look at probing class and method information directly using the objc runtime API which will yield you SEL as well.

You could also have the JNI code have vars defined for the selectors it will need to do its bridging work without the need to look them up (@selector(blah)).

It is non-trivial (to some extent) to deal with the rules of when to use the various objc_msgSend varients.

-Shawn