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:Duncan McGregor (dun@oneeyedmen.com)
Date:Nov 14, 2007 12:49:58 pm
List:net.java.dev.jna.users

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.

I hope to have a reasonably general purpose Cocoa wrapper to contribute soon.

Duncan

public interface FoundationLibrary extends Library { public static FoundationLibrary library = (FoundationLibrary) Native.loadLibrary("Foundation", FoundationLibrary.class);

void NSLog(Pointer pString, Pointer thing);

Pointer CFStringCreateWithCString(Pointer allocator, String string, int encoding);

String CFStringGetCStringPtr(Pointer string, int encoding);

Pointer objc_getClass(String className);

Pointer class_createInstance(Pointer pClass, int extraBytes);

Pointer NSSelectorFromString(Pointer nssSelectorName);

Pointer objc_msgSend(Pointer receiver, Pointer selector, Pointer... args); }