我已经使用JNAerator将.dll库转换为JAR。现在我需要调用如下所示的OpenTCPIPPort_V方法:public static short OpenTCPIPPort_V(Pointer<Byte > tcpPort, Pointer<Byte > IPAddr)
如何将两个字符串值传递给此方法?
发布于 2013-01-13 04:45:36
有一个来自字符串类的名为getBytes的函数。下面是一个示例:
String example = "example, string";
byte[] bytes = example.getBytes();您现在需要做的就是将这些byte[]值放入您的指针中。我想你现在可以处理了。
发布于 2013-01-13 16:23:16
我找到了解决方案。这是Pointer<Byte> org.bridj.Pointer.pointerToCString(String string)方法
发布于 2013-02-22 02:18:59
我为Tektronix(用于控制来自TekVisa的测量仪器的DLL )尝试了pointerToCString,但它不能打开仪器会话。这个线程中的第二个答案更好,但忽略了一个细节:字节数组必须以0结束。我下面的代码可以工作。(仪器变量的类型为字符串,包含仪器字符串,例如“TCPIP:INSTR”。)
有趣的是,pointerToCString在向仪器发送命令时起作用,例如viWrite("*IDN?")。
Pointer<Byte> pViString = Pointer.allocateBytes(instrument.length() + 1);
byte[] instrumentBytes = instrument.getBytes();
pViString.setBytes(instrumentBytes);
pViString.setByteAtIndex(instrument.length(), (byte) 0);https://stackoverflow.com/questions/14297709
复制相似问题