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:Timothy Wall (twa@users.sf.net)
Date:Nov 14, 2007 5:34:43 am
List:net.java.dev.jna.users

On Nov 13, 2007, at 9:51 PM, Michael Hall wrote:

On Nov 13, 2007, at 8:11 PM, Timothy Wall wrote:

(Forwarded from the JNA users' list)

Begin forwarded message:

From: Duncan McGregor <dun@oneeyedmen.com> Date: November 13, 2007 7:10:34 PM EST To: use@jna.dev.java.net Subject: [jna-users] Accessing static Objective-C from JNA Reply-To: use@jna.dev.java.net

Hi, I'm hoping that some Mac guru can help out.

I'd like to wrap some Cocoa on the Mac. In order to do this I need to create NSString objects, passing them as id (int or long I guess) through JNA.

The function to create an NSString from a C string is NSString::stringWithUTF8String:(const char *). This is a static method on NSString, defined in NSString.h and hence linked from Foundation.Framework

I'd like to persuade the following to work

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

int stringWithUTF8String(String string); }

While I can call plain C functions in Foundation, attempting to call stringWithUTF8String gives java.lang.UnsatisfiedLinkError: Cannot locate function 'stringWithUTF8String' at com.sun.jna.NativeLibrary.getFunctionAddress (NativeLibrary.java:228)

Am I being optimistic in hoping that, as stringWithUTF8String is static in NSString, that some naming convention will allow me to access it without dropping down into the JNI code that we're all here to avoid?

You don't indicate why you are forwarding this to this list. I don't know that we can speak to what jna provides as well as you yourself can.

I recall seeing mention (on this list or another) of some C- accessible functions for manipulating objc objects. A quick google didn't turn up what I thought I'd seen.

JNA provides access to shared libraries presenting a C calling convention; the original poster needs to be directed to references on accessing ObjC in that manner. It may be that JNA may not be appropriate for ObjC interop, or that a shim layer would be useful, or something else (maybe JNIDirect?).

You can't just get to ObjectiveC code through naming conventions as far as I know. You need to use the ObjectiveC runtime including the message sending functionality like... public static native int objc_msgSend(int self, int op); My JNIDirect for this has very roughly about 50 overloaded signatures of this method in a later version. You could probably get by more simply for what is wanted here but the only non-ObjectiveC interface I know of is through the runtime methods.

Thanks,