com.sun.jna.Pointer,读取字节数据

示例:读取前四个字节数据


Pointer pBuffer//返回数据


HCNetSDK.REMOTECONFIGSTATUS struCfgStatus  = new HCNetSDK.REMOTECONFIGSTATUS();
struCfgStatus.write();
Pointer pCfgStatus = struCfgStatus.getPointer();
pCfgStatus.write(0, pBuffer.getByteArray(0, struCfgStatus.size()), 0,struCfgStatus.size());
struCfgStatus.read();

int iStatus = 0;
for(int i=0;i<4;i++)
{
    int ioffset = i*8;
    int iByte = struCfgStatus.byStatus[i]&0xff;
    iStatus = iStatus + (iByte << ioffset);
}





public static class REMOTECONFIGSTATUS extends Structure {
   public byte[] byStatus = new byte[4];
   public byte[] byErrorCode = new byte[4];
}

 

你可能感兴趣的:(java,JNA)