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 (twal@dev.java.net)
Date:Nov 14, 2007 5:58:09 am
List:net.java.dev.jna.users

Take a look at http://jnidirect.org/examples.html for examples of accessing ObjC via C calling convention. You ought to be able to use the same methods using JNA (or JNIDirect may suit your needs).

Please feel free to post an example once you get it working, I can add it to the contrib area.

On Nov 13, 2007, at 7:10 PM, Duncan McGregor wrote:

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?

Thanks in anticipation