在JNA中正确映射SHChangeNotify

时间:2011-12-01 09:47:28

标签: java jna

这是来自MSDN的SHChangeNotify函数的语法:

void SHChangeNotify(
  LONG wEventId,
  UINT uFlags,
  __in_opt  LPCVOID dwItem1,
  __in_opt  LPCVOID dwItem2
);

我要在Java Native Access [JNA]中编写Java对应物,但这个声明似乎是错误的:

public interface Shell32 extends com.sun.jna.platform.win32.Shell32 {

    public Shell32 INSTANCE = (Shell32) Native.loadLibrary(Shell32.class);

    void SHChangeNotify(long wEventId, int uFlags, Pointer dwItem1, Pointer dwItem2);

}

我遇到以下异常:

  

线程“main”中的异常java.lang.UnsatisfiedLinkError:错误   查找功能'SHChangeNotify'

知道怎么写得正确吗?

1 个答案:

答案 0 :(得分:1)

不是从com.sun.jna.platform.win32.Shell32扩展Shell32接口,而是从StdCallLibrary

扩展它
public interface Shell32 extends StdCallLibrary {
    final static Map<String, Object> WIN32API_OPTIONS = new HashMap<String, Object>() {
        private static final long serialVersionUID = 1L;
        {
            put(Library.OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
            put(Library.OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
        }
    };

    public Shell32 INSTANCE = (Shell32) Native.loadLibrary("Shell32", Shell32.class, WIN32API_OPTIONS);

    //whatever you want to expose here
}