gpt4 book ai didi

Java JNA 无法在 Kernel32 中找到命名管道函数

转载 作者:行者123 更新时间:2023-11-30 02:53:55 25 4
gpt4 key购买 nike

所以我有这个“Beep”功能,但当我尝试任何命名管道功能时,它会返回:

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,并且是 WaitNamedPipeAWaitNamedPipeW,具体取决于调用者是否分别使用 ANSII 或 UNICODE。来源(请参阅 Unicode 和 ANSI 名称部分):https://msdn.microsoft.com/en-us/library/windows/desktop/aa365800(v=vs.85).aspx

关于Java JNA 无法在 Kernel32 中找到命名管道函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37813013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com