13 messages in net.java.dev.jna.usersRe: [jna-users] Cannot pass any data ...
FromSent OnAttachments
Daniel HorowitzJun 14, 2007 11:27 am 
Timothy WallJun 14, 2007 11:29 am 
Daniel HorowitzJun 14, 2007 11:31 am 
Daniel HorowitzJun 14, 2007 11:39 am 
Timothy WallJun 14, 2007 11:42 am 
Daniel HorowitzJun 14, 2007 11:52 am 
Timothy WallJun 14, 2007 11:53 am 
Timothy WallJun 14, 2007 12:03 pm 
Daniel HorowitzJun 14, 2007 12:13 pm 
Daniel HorowitzJun 14, 2007 12:22 pm 
Timothy WallJun 14, 2007 12:30 pm 
Daniel HorowitzJun 14, 2007 2:11 pm 
Timothy WallJun 14, 2007 2:23 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] Cannot pass any data to native dllActions...
From:Timothy Wall (twal@dev.java.net)
Date:Jun 14, 2007 12:03:26 pm
List:net.java.dev.jna.users

On Jun 14, 2007, at 2:53 PM, Daniel Horowitz wrote:

I changed my function to __stdcall

extern "C" __declspec(dllexport)int __stdcall subscribe(int foo);

int __stdcall subscribe(int foo) { return 0; }

and I changed my java interface to extend Library

Now I am getting -

Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot locate function 'subscribe'

Slow down, Tonto.

If your functions are stdcall, use StdCallLibrary. If they're not, use Library. Don't mix. Unless you have a reason to make them stdcall, don't. Your build, linkage, and interop will be simpler.

If you decide you really need stdcall, when building your dll, the default symbol exported for the above function is subscribe@4. If you're using the latest trunk build, you can add the StdCallFunctionMapper to the options passed to Native.loadLibrary, e.g.

interface MyLibrary extends StdCallLibrary { MyLibrary INSTANCE = (MyLibrary)Native.loadLibrary("mylib", MyLibrary.class, new HashMap() {{ put(OPTION_FUNCTION_MAPPER, FUNCTION_MAPPER); }}); ...

The reason you don't have to do this for w32 API dlls is that microsoft has exported undecorated versions ("subscribe" rather than "subscribe@4") of all the functions. You can also do this by using a DEF file to define the symbols you want exported in your link step (don't know if VS2005 has any IDE magic to do so, though).