Java JNA 在 Kernel32 中找不到命名管道函数
Java JNA cant find namedpipe functions in Kernel32
所以我有这个 "Beep" 函数可以工作,但是当我尝试任何 namedpipe 函数时它 returns :
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error
looking up function 'WaitNamedPipe': The specified procedure could not
be found.
import java.nio.charset.StandardCharsets;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
/**
* @author
*
*/
public class NamedPipeNativeFunctions {
/*
* Public Declare Function CallNamedPipe Lib "kernel32" Alias
* "CallNamedPipeA" (ByVal lpNamedPipeName As String, lpInBuffer As Any,
* ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As
* Long, lpBytesRead As Long, ByVal nTimeOut As Long) As Long
*
*/
public interface Kernel32 extends Library {
public long CallNamedPipe (String lpNamedPipeName,long lpInBuffer ,long nInBufferSize, Pointer lpOutBuffer,long nOutBufferSize, Pointer lpBytesRead, long nTimeOut);
public boolean WaitNamedPipe(String lpNamedPipeName,
int nTimeOut);
public boolean Beep(int FREQUENCY, int DURATION);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
myClass myclass = new myClass () ;
myClass myclass2 = new myClass () ;
Pointer lpOutBuffer = myclass.getPointer() ;
Pointer lpBytesRead =myclass2.getPointer() ;
Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
//lib.CallNamedPipe("1234TestPipe", 255, 255, lpOutBuffer , 255, lpBytesRead , 5000);
lib.Beep(698, 500); // works
boolean sucess = lib.WaitNamedPipe("hgf" ,(int) 5000 ); // does not work
}
}
WaitNamedPipe
是一个#define 并且是WaitNamedPipeA
或WaitNamedPipeW
取决于调用者分别使用ANSII 还是UNICODE。来源(参见 Unicode 和 ANSI 名称部分):https://msdn.microsoft.com/en-us/library/windows/desktop/aa365800(v=vs.85).aspx
所以我有这个 "Beep" 函数可以工作,但是当我尝试任何 namedpipe 函数时它 returns :
Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'WaitNamedPipe': The specified procedure could not be found.
import java.nio.charset.StandardCharsets;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
/**
* @author
*
*/
public class NamedPipeNativeFunctions {
/*
* Public Declare Function CallNamedPipe Lib "kernel32" Alias
* "CallNamedPipeA" (ByVal lpNamedPipeName As String, lpInBuffer As Any,
* ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As
* Long, lpBytesRead As Long, ByVal nTimeOut As Long) As Long
*
*/
public interface Kernel32 extends Library {
public long CallNamedPipe (String lpNamedPipeName,long lpInBuffer ,long nInBufferSize, Pointer lpOutBuffer,long nOutBufferSize, Pointer lpBytesRead, long nTimeOut);
public boolean WaitNamedPipe(String lpNamedPipeName,
int nTimeOut);
public boolean Beep(int FREQUENCY, int DURATION);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
myClass myclass = new myClass () ;
myClass myclass2 = new myClass () ;
Pointer lpOutBuffer = myclass.getPointer() ;
Pointer lpBytesRead =myclass2.getPointer() ;
Kernel32 lib = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
//lib.CallNamedPipe("1234TestPipe", 255, 255, lpOutBuffer , 255, lpBytesRead , 5000);
lib.Beep(698, 500); // works
boolean sucess = lib.WaitNamedPipe("hgf" ,(int) 5000 ); // does not work
}
}
WaitNamedPipe
是一个#define 并且是WaitNamedPipeA
或WaitNamedPipeW
取决于调用者分别使用ANSII 还是UNICODE。来源(参见 Unicode 和 ANSI 名称部分):https://msdn.microsoft.com/en-us/library/windows/desktop/aa365800(v=vs.85).aspx