sino sino - 4 months ago 14
Java Question

Java JNA cant find namedpipe functions in Kernel32

So I have this "Beep" function works , but when I try any of namedpipe function it 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 is a #define and is either WaitNamedPipeA or WaitNamedPipeW depending if the caller is using ANSII or UNICODE respectively. Source (see Unicode and ANSI names section):