Java调用Windows API GetShortPathName

我想在我的java类中使用本机windows api函数。

我感兴趣的function是GetShortPathName。 http://msdn.microsoft.com/en-us/library/aa364989%28VS.85%29.aspx

我尝试使用这个 – http://dolf.trieschnigg.nl/eightpointthree/eightpointthree.html但是在某些情况下,当我使用它时java完全崩溃,所以它不适合我。

问题是我是否必须在例如C中编写代码,生成DLL然后在JNI / JNA中使用该DLL? 或者我可能以某种方式以不同的方式访问系统API?

我将非常感谢您的评论。 如果你可以发布一些代码作为例子,我将不胜感激。

我找到了使用JNA的答案

import com.sun.jna.Native; import com.sun.jna.platform.win32.Kernel32; public class Utils { public static String GetShortPathName(String path) { byte[] shortt = new byte[256]; //Call CKernel32 interface to execute GetShortPathNameA method int a = CKernel32.INSTANCE.GetShortPathNameA(path, shortt, 256); String shortPath = Native.toString(shortt); return shortPath; } public interface CKernel32 extends Kernel32 { CKernel32 INSTANCE = (CKernel32) Native.loadLibrary("kernel32", CKernel32.class); int GetShortPathNameA(String LongName, byte[] ShortName, int BufferCount); } } 

谢谢你的提示。 以下是我改进的function。 它使用Unicode版本的GetShortPathName

 import com.sun.jna.Native; import com.sun.jna.platform.win32.Kernel32; public static String GetShortPathName(String path) { char[] result = new char[256]; Kernel32.INSTANCE.GetShortPathName(path, result, result.length); return Native.toString(result); }