4 messages in net.java.dev.jna.usersRe: [jna-users] calling a static func...
FromSent OnAttachments
Travis BanksFeb 3, 2009 2:07 pm 
Daniel KaufmannFeb 3, 2009 3:40 pm 
Steve Sobol (JDN)Feb 3, 2009 5:52 pm 
LYou...@gkservices.comFeb 4, 2009 7:55 am 
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] calling a static function from JavaActions...
From:LYou...@gkservices.com (LYou@gkservices.com)
Date:Feb 4, 2009 7:55:23 am
List:net.java.dev.jna.users

Write a C wrapper .dll to delegate and be done with it.

Levi Yourchuck Senior Programmer Analyst G&K Services Phone: 952 912 5828 www.gkservices.com Enhancing Image & Safety Through Innovation This e-mail and any attachments may contain confidential and privileged information. If you are not the intended recipient, please notify the sender immediately by return e-mail, delete this e-mail and destroy any copies. Any dissemination or use of this information by a person other than the intended recipient is unauthorized and may be illegal.

Daniel Kaufmann <dani@gmail.com> 02/03/2009 05:41 PM Please respond to use@jna.dev.java.net

To use@jna.dev.java.net cc

Subject Re: [jna-users] calling a static function from Java

Hello Travis, jna does not have any special support for C++, only for C. However, in some cases you can call a C++ function from JNA. In your case you first need to understand how is your function exported in the library (.dll/.so) you are trying to call. According to your mail your are trying to call a static function. However, if you specify static for a free function, it means you are asking for Internal linkage, so it is only available in the same C file where you are compiling, so I think it won't be exported so you can't call it from jna. On the other hand if the it is actually a static function of a C++ class, then it can be exported but the name of the exported function is mangled. You can check the exported names for the library using Dependency Walker program in Windows or nm command in linux or cygwin (check "My library mapping causes an UnsatisfiedLinkError" in jna home page). For demangling (showing similar to how you declare it in C++) the function name, in case you are not sure you have found the right function, you can use the option for that in Dependency Walker if you are using Microsoft C++ compiler or c++filt in linux or cygwin. Once you have the mangled name for the function, you can use that name in java or use a FunctionMapper or InvocationMapper. Since the parameters are primitive types and arrays and not classes, I believe you should be able to call the function from jna. Regards, Daniel

On 2/3/09, Travis Banks <trav@gmail.com> wrote: Hello All,

I'm having difficulty declaring a method to call a c++ static function from my library interface file. The native signature is; static void bubble(int *data, int num_data); If I use the following Java interface method; static void bubble(int[] data, int num_data); I get an Illegal Modifier error from my IDE (interfaces can only have public and abstract as modifiers. If I remove 'static' from the interface method I get an UnsatisfiedLinkError when I try to run the program (Error looking up function 'bubble').

How can I call the static function 'bubble' from Java? Thanks for any help you can give me.

- Travis