开发者

The specified procedure could not be found (MapVirtualKeyEx) JNA (Java)

I am using JNA and need to use the MapVirtualKeyEx function.

Here is the signature:

UINT WINAPI MapVirtualKeyEx(

      __in         UINT uCode,
      __in         UINT uMapType,
      __inout_opt  HKL dwhkl
    );

More information on the signature can be found here: http://msdn.microsoft.com/en-us/library/ms646307(v=vs.85).a开发者_开发技巧spx

I tried this:

int MapVirtualKeyEx (int uCode, int nMapType, int dwhkl);

but it didn't match. I have a feeling it's the _inout_opt that's causing the problem.

The error I get is : The specified procedure could not be found.

        static interface User32 extends Library {
                public static User32 INSTANCE = (User32) Native.loadLibrary("User32", 
                User32.class);

                int MapVirtualKeyEx (int uCode, int nMapType, int dwhkl);
            }


            private static void test(int keyCode)
            {

                int code = User32.INSTANCE.MapVirtualKeyEx(key, MAPVK_VK_TO_VSC,
                    134809609); //The number is the keyboard ID, it's temporary.

            }

I also have another question: Is there some kind of automated way of converting the API signature so it can be used in JNI/JNA?


Since MapVirtualKeyEx() deals with characters there is an ANSI and WIDE version of it. Therefore the function is MapVirtualKeyExA()/MapVirtualKeyExW() depending which one you want to use.


For a parameter that is both an input and output parameter, you will need to use one of the JNA reference types. If HKL is indeed an int, use IntByReference. If it's a struct, you'll need to define a corresponding Structure.

As for your other question, try JNAerator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜