所以我有这个“Beep”功能,但是当我尝试任何一个namedpipe函数时它会返回:
线程“main”中的异常java.lang.UnsatisfiedLinkError:错误 查找函数'WaitNamedPipe':指定的过程不能 被发现。
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
}
}
答案 0 :(得分:2)
WaitNamedPipe
是#define,可以是WaitNamedPipeA
或WaitNamedPipeW
,具体取决于调用者是分别使用ANSII还是UNICODE。源(请参阅Unicode和ANSI名称部分):https://msdn.microsoft.com/en-us/library/windows/desktop/aa365800(v=vs.85).aspx