5 messages in net.java.dev.jna.usersRe: [jna-users] Can't Find Native Fun...
FromSent OnAttachments
Dick AdamsDec 27, 2008 6:15 pm 
Timothy WallDec 28, 2008 12:18 am 
Dick AdamsDec 28, 2008 5:33 am 
Timothy WallDec 28, 2008 9:09 am 
Steve Sobol (JDN)Dec 28, 2008 9:47 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] Can't Find Native FunctionActions...
From:Timothy Wall (twal@dev.java.net)
Date:Dec 28, 2008 9:09:15 am
List:net.java.dev.jna.users

Look at the source for com.sun.jna.examples.win32.W32API. There are default library options already defined.

Function mapping is described here:
https://jna.dev.java.net/javadoc/overview-summary.html #function-mapping.

If you choose to reimplement your own options, the Library option keys are described here:
https://jna.dev.java.net/nonav/javadoc/com/sun/jna/Library.html .

You need OPTION_FUNCTION_MAPPER, with a FunctionMapper implementation, and probably OPTION_TYPE_MAPPER with a TypeMapper implementation. Implementations of both of these are in com.sun.jna.win32.

On Dec 28, 2008, at 8:33 AM, Dick Adams wrote:

Sorry if I'm dense, but I don't understand:

1. I found the Kernel32 constant for the archive bit, but can't find documentation about "function name mapping". Is there is a link to it from the JNA home page? I tried Google,but that didn't yield anything, nor did the search box on the JNA home page.

2. What does GetFileAttributes{A|W} mean?

3. I see the options map parameter to Native.loadLibrary, but the Javadocs don't tell what library options are or when/why to use them.

I know this seems like a simple problem to solve, but I've been reading the site documentation for a day now & can't figure it out. Would greatly appreciate some insight, or a short example on how to all this function.

At 03:18 AM 12/28/2008 -0500, you wrote:

Look at the JNA example kernel32 API definition, including the options passed to the Native.loadLibrary call.

There is a function name mapper which converts GetFileAttributes into GetFileAttributes{A|W}.

On Dec 27, 2008, at 9:16 PM, Dick Adams wrote:

I'm getting an error message trying to call the Windows GetFileAttributes() function (I'm running Windows XP). Can anyone see what I'm doing wrong?

ERROR MESSAGE:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'GetFileAttributes': The specified procedure could not be found.

at com.sun.jna.Function.<init>(Function.java:129) at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:250) at com.sun.jna.Library$Handler.invoke(Library.java:191) at $Proxy0.GetFileAttributes(Unknown Source) at com.atomware.Publisher.accept(Publisher.java:70) at com.atomware.io.Directory.accept(Directory.java:80) at java.io.File.listFiles(Unknown Source) at com.atomware.io.Directory.getMatchingFiles(Directory.java:107) at com.atomware.io.TreeWalker.walk(TreeWalker.java:53) at com.atomware.Publisher.publish(Publisher.java:87) at com.atomware.Publisher.main(Publisher.java:33)

CODE:

import java.io.File;

import com.sun.jna.Native; import com.sun.jna.win32.StdCallLibrary;

/** * Provides access to the Microsoft Windows KERNEL32.DLL. */ public class WindowsKernel {

// = = = = = = = = = = = = = = = = = = = = = = = = = = ==================================================================== /** * Accesses native Windows API from Java */ public interface API extends StdCallLibrary {

/** The API Instance */ API INSTANCE = (API)Native.loadLibrary(LIBRARY_NAME, API.class);

/** * Retrieves a set of FAT file system attributes for a specified file or directory. * Many file attributes are already from the Java {@link File} class, but certain ones, * such as the archive bit, are available only by calling this method. * @param fileName The file name. * @return The bit-mapped attributes. */ int GetFileAttributes(String fileName); } // = = = = = = = = = = = = = = = = = = = = = = = = = = ====================================================================

/** Value: {@value} */ public static final String LIBRARY_NAME = "C:/WINDOWS/SYSTEM32/ kernel32.dll"; }