From bf8cb8a192452d7e6bc5c079cd38823db9b84111 Mon Sep 17 00:00:00 2001 From: kobevaliant Date: Fri, 12 Aug 2016 13:23:37 +0800 Subject: [PATCH 1/4] Update dispatch.c add win32 DLL ordinal value function support --- native/dispatch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/native/dispatch.c b/native/dispatch.c index 3712e12e87..5e74be01f5 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -310,6 +310,7 @@ w32_short_name(JNIEnv* env, jstring str) { static HANDLE w32_find_entry(JNIEnv* env, HANDLE handle, const char* funname) { + if (funcname[0] == '#') funname = (const char *)atoi(funname + 1); void* func = NULL; if (handle != GetModuleHandle(NULL)) { func = GetProcAddress(handle, funname); From 7f662cdf5c4b09fd2f3367fea9d7c6beac502b50 Mon Sep 17 00:00:00 2001 From: kobevaliant Date: Mon, 15 Aug 2016 14:05:48 +0800 Subject: [PATCH 2/4] Create W32OrdinalNumberFunctionTest.java add some test code about win32 ordinal number function --- .../win32/W32OrdinalNumberFunctionTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 test/com/sun/jna/win32/W32OrdinalNumberFunctionTest.java diff --git a/test/com/sun/jna/win32/W32OrdinalNumberFunctionTest.java b/test/com/sun/jna/win32/W32OrdinalNumberFunctionTest.java new file mode 100644 index 0000000000..114217f15f --- /dev/null +++ b/test/com/sun/jna/win32/W32OrdinalNumberFunctionTest.java @@ -0,0 +1,60 @@ +package com.sun.jna.win32; + +import com.sun.jna.FunctionMapper; +import com.sun.jna.Library; +import com.sun.jna.Native; +import com.sun.jna.NativeLibrary; +import junit.framework.TestCase; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +public class W32OrdinalNumberFunctionTest extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(W32OrdinalNumberFunctionTest.class); + } + + @Target({ElementType.METHOD}) + @Retention(RetentionPolicy.RUNTIME) + public @interface FuncName { + String value(); + } + + public interface CLibrary extends Library { + @FuncName("#1206") + double sin(double x); + } + + CLibrary c; + + public class MyFunctionMapper implements FunctionMapper { + @Override + public String getFunctionName(NativeLibrary library, Method method) { + FuncName fn = method.getAnnotation(FuncName.class); + return fn == null ? method.getName() : fn.value(); + } + } + + @Override + protected void setUp() throws Exception { + Map map = new HashMap(); + map.put(Library.OPTION_FUNCTION_MAPPER, new MyFunctionMapper()); + c = (CLibrary) Native.loadLibrary("msvcrt", CLibrary.class, map); + } + + @Override + protected void tearDown() throws Exception { + c = null; + } + + public void testOrdinalNumberFunction() { + double y = c.sin(Math.PI / 2); + assertTrue(Math.abs(y - 1) < 0.0001); + } +} From 91ec05939548e9ca997e2d469622b204c11d875e Mon Sep 17 00:00:00 2001 From: kobevaliant Date: Mon, 15 Aug 2016 14:11:53 +0800 Subject: [PATCH 3/4] correct spelling --- native/dispatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/dispatch.c b/native/dispatch.c index 5e74be01f5..d299a86474 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -310,7 +310,7 @@ w32_short_name(JNIEnv* env, jstring str) { static HANDLE w32_find_entry(JNIEnv* env, HANDLE handle, const char* funname) { - if (funcname[0] == '#') funname = (const char *)atoi(funname + 1); + if (funname[0] == '#') funname = (const char *)atoi(funname + 1); void* func = NULL; if (handle != GetModuleHandle(NULL)) { func = GetProcAddress(handle, funname); From ec28a41118ff10fc2aac57c46011b91364321085 Mon Sep 17 00:00:00 2001 From: kobevaliant Date: Tue, 16 Aug 2016 09:54:32 +0800 Subject: [PATCH 4/4] NULL checking --- native/dispatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/dispatch.c b/native/dispatch.c index d299a86474..2da47aafc0 100644 --- a/native/dispatch.c +++ b/native/dispatch.c @@ -310,7 +310,7 @@ w32_short_name(JNIEnv* env, jstring str) { static HANDLE w32_find_entry(JNIEnv* env, HANDLE handle, const char* funname) { - if (funname[0] == '#') funname = (const char *)atoi(funname + 1); + if (funname && funname[0] == '#') funname = (const char *)atoi(funname + 1); void* func = NULL; if (handle != GetModuleHandle(NULL)) { func = GetProcAddress(handle, funname);