ファイルが別のプロセスで使用されているかどうかを確認するために、この回答CreateFile
のJava実装を行うことを目的として、JNAを使用してWindows7でWin32の関数を呼び出そうとしています。
私がこれまでに持っているコードは次のとおりです。
import com.sun.jna.Native;
import com.sun.jna.examples.win32.Kernel32;
public class CreateFileExample {
static int GENERIC_ACCESS = 268435456;
static int EXCLUSIVE_ACCESS = 0;
static int OPEN_EXISTING = 3;
public static void main(String[] args) {
Kernel32 kernel32 =
(Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
kernel32.CreateFile("c:\\file.txt", GENERIC_ACCESS, EXCLUSIVE_ACCESS,
null, OPEN_EXISTING, 0, null);
}
}
ただし、これを実行すると例外が発生します。
java.lang.UnsatisfiedLinkError: Error looking up function 'CreateFile': The specified procedure could not be found.
呼び出しを無効なものに変更"kernel32"
すると、代わりに、DLLがライブラリパスから正しく検出されていることを示しますが、呼び出し方法に問題があります。loadLibrary
The specified module could not be found
CreateFile
私が間違っていることについて何か考えはありますか?
CreateFile
で定義されcom.sun.jna.examples.win32.Kernel32
ています:
public abstract com.sun.jna.examples.win32.W32API.HANDLE CreateFile(
java.lang.String arg0,
int arg1,
int arg2,
com.sun.jna.examples.win32.Kernel32.SECURITY_ATTRIBUTES arg3,
int arg4,
int arg5,
com.sun.jna.examples.win32.W32API.HANDLE arg6);