質問

Win32に電話しようとしています CreateFile JNAを使用してWindows7で機能します。 この答え ファイルが別のプロセスで使用されているかどうかを確認します。

私がこれまでに持っているコードは次のとおりです。

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" の中に loadLibrary 無効なものを呼び出してから、代わりに私は得ます The specified module could not be found したがって、これはDLLがライブラリパスから正しく発見されていることを示唆していますが、私が呼んでいる方法に何か問題があります 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);

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top