JNA getFieldOrder() results in names not matching in HashSet() comparison (JNA's Structure.java, line 925)

StackOverflow https://stackoverflow.com/questions/23690307

Question

Running into a maddening blocking error:

Exception in thread "main" java.lang.Error: Structure.getFieldOrder() on class com.luke.generator.GeneratorEngine$VERSION_INFO returns names ([BuildString, ProtocolMajorVer, ProtocolMinorVer]) which do not match declared field names ([BiuldString, ProtocolMajorVer, ProtocolMinorVer])

   at com.sun.jna.Structure.getFields(Structure.java:925)
   at com.sun.jna.Structure.deriveLayout(Structure.java:1058)
   at com.sun.jna.Structure.calculateSize(Structure.java:982)
   at com.sun.jna.Structure.calculateSize(Structure.java:949)
   at com.sun.jna.Structure.allocateMemory(Structure.java:375)
   at com.sun.jna.Structure.<init>(Structure.java:184)
   at com.sun.jna.Structure.<init>(Structure.java:172)
   at com.sun.jna.Structure.<init>(Structure.java:159)
   at com.sun.jna.Structure.<init>(Structure.java:151)
   at com.luke.generator.GeneratorEngine$.<init>(GeneratorEngine.java:108)
   at com.luke.generator.connectionVersion(GeneratorEngine.java:297)
   at com.luke.generator.Main.main(Main.java:161)

Platform: Intel, Windows 8 JRE 1.7, 32-bit (x86) Eclipse Kepler, Default encoding UTF-8 jna-4.1.0.jar 32-bit CPP DLL - I can confirm that I am loading the library and calling functions that do not include parameters. I also tried passing WStrings and Strings, but that did not address the issue.

Source:

CPP struct:

typedef struct {
    UINT32    ProtocolMajorVer;
    UINT32    ProtocolMinorVer;
    UI_STRING BuildString;      // Build version for the application.
 } VERSION_INFO;

CPP Function

DLL_EXPORTS RETURN_TYPES ConnectionVersion (VERSION_INFO    &Version) {<body omitted>}

Java code:

//Interface definition
public interface UiApi extends StdCallLibrary {

          UiApi INSTANCE = (UiApi) Native.loadLibrary(UiApiPath,UiApi.class);

          final String PROTOCOLMAJORVERSION = new String("ProtocolMajorVer");
          final String PROTOCOLMINORVERSION = new String("ProtocolMinorVer");
          final String BUILDSTRING = new String("BuildString");


          public static class VERSION_INFO extends Structure {

                 public static class ByReference extends VERSION_INFO implements Structure.ByReference {}
                 public static class ByValue extends VERSION_INFO implements Structure.ByValue {}

                 public int ProtocolMajorVer;
                 public int ProtocolMinorVer;
                 public byte[] BiuldString;


                 protected List getFieldOrder() {
                       return Arrays.asList(new String[] { "ProtocolMajorVer","ProtocolMinorVer","BuildString" });
                 }
          }

          //Connection 
          public int Connect(byte[] strServerName);      
          public int Disconnect();
          public int CloseProject();

          public int ConnectionVersion(VERSION_INFO result);
          public int ConnectionVersion(VERSION_INFO.ByReference result);
          public int ConnectionVersion(VERSION_INFO.ByValue result);


   }

//Engine.connectionVersion() method
public static int connectionVersion() {

          int nReturn = 0;
          String str = new String("This is my build version\n");

          UiApi uiapilib;

          uiapilib = UiApi.INSTANCE;

          try {

                 UiApi.VERSION_INFO.ByReference result = new UiApi.VERSION_INFO.ByReference();


                 result.ProtocolMajorVer = 0;
                 result.ProtocolMinorVer = 0;
                 result.BiuldString = str.getBytes();

                 nReturn = uiapilib.ConnectionVersion(result);
          }
          catch (Exception e) {
                 System.out.println("Error=" + e.getLocalizedMessage());

          }

          return nReturn;           

   }


  //This is the code in main that results in exception


  private static Engine engine;

  engine = new GeneratorEngine();
  engine.connectionVersion();

I must be missing something basic. Is there something in Eclipse that could possibly be causing the HashSet name comparisons in JNA's Structure.java (line 925) that would result in names not matching? From the exception thrown, these definitions look identical.

Thanks for any tips, guidance, fresh perspectives you can offer.

Was it helpful?

Solution

Check your spelling - the field is called BiuldString not BuildString, you have the i and u reversed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top