Java クラスでネイティブ Windows API 関数を使用したいと考えています。
私が興味を持っている関数は GetShortPathName です。 http://msdn.microsoft.com/en-us/library/aa364989%28VS.85%29.aspx
私はこれを使用しようとしました - http://dolf.trieschnigg.nl/eightpointthree/eightpointthree.html しかし、状況によっては、Java を使用すると完全にクラッシュするため、これはオプションではありません。
問題は、たとえば C でコードを記述し、DLL を作成してから、その DLL を JNI/JNA で使用する必要があるかどうかです。それとも、別の方法でシステム 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);
}
}