66import java .nio .CharBuffer ;
77import java .io .UnsupportedEncodingException ;
88import com .sun .jna .ptr .IntByReference ;
9+ import com .sun .jna .ptr .LongByReference ;
10+ import java .math .BigInteger ;
911import java .util .ArrayList ;
1012import java .util .List ;
1113
@@ -24,6 +26,11 @@ public class LexFloatClient {
2426 */
2527 public static final int LF_FAIL = 1 ;
2628
29+ // Convert long to BigInteger to correctly handle unsigned 64-bit values
30+ private static BigInteger toUnsignedBigInteger (long value ) {
31+ return BigInteger .valueOf (value ).and (BigInteger .valueOf (0xFFFFFFFFFFFFFFFFL ));
32+ }
33+
2734 /**
2835 * Sets the product id of your application
2936 *
@@ -257,19 +264,20 @@ public static String GetHostLicenseMetadata(String key) throws LexFloatClientExc
257264 */
258265 public static HostLicenseMeterAttribute GetHostLicenseMeterAttribute (String name ) throws LexFloatClientException , UnsupportedEncodingException {
259266 int status ;
260- IntByReference allowedUses = new IntByReference (0 );
261- IntByReference totalUses = new IntByReference (0 );
262- IntByReference grossUses = new IntByReference (0 );
267+ LongByReference allowedUses = new LongByReference (0 );
268+ // These references can still hold the uint64_t values populated by the native function
269+ LongByReference totalUses = new LongByReference (0 );
270+ LongByReference grossUses = new LongByReference (0 );
263271
264272 if (Platform .isWindows ()) {
265273 status = LexFloatClientNative .GetHostLicenseMeterAttribute (new WString (name ), allowedUses , totalUses , grossUses );
266274 if (LF_OK == status ) {
267- return new HostLicenseMeterAttribute (name , allowedUses .getValue (), totalUses .getValue (), grossUses .getValue ());
275+ return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedBigInteger ( totalUses .getValue ()), toUnsignedBigInteger ( grossUses .getValue () ));
268276 }
269277 } else {
270278 status = LexFloatClientNative .GetHostLicenseMeterAttribute (name , allowedUses , totalUses , grossUses );
271279 if (LF_OK == status ) {
272- return new HostLicenseMeterAttribute (name , allowedUses .getValue (), totalUses .getValue (), grossUses .getValue ());
280+ return new HostLicenseMeterAttribute (name , allowedUses .getValue (), toUnsignedBigInteger ( totalUses .getValue ()), toUnsignedBigInteger ( grossUses .getValue () ));
273281 }
274282 }
275283 throw new LexFloatClientException (status );
0 commit comments