• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java data type compatible to record in Delphi

 
Greenhorn
Posts: 4
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am writing code for calling dll functions from java. I am using JNA (Java native access) library for it.
There is one function in DLL which takes Delphi record (just like structure in C) as argument.
For this I created a class having attributes same as that of in delphi record & passed its object as argument
while calling that DLL function.But I am getting java.lang.IllegalArgumentException.

I understand that a C like structure in java is nothing but a class itself. But is there any other type or class
from Java collection similar to record in Delphi?

Thanks.

Regards,
Saurabh
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us the Delphi record definition and its matching definition in Java?
 
Saurabh Bhandarkar
Greenhorn
Posts: 4
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,
here is the Delphi record definition

TSHREEDATA = RECORD
SHREE_ERROR : BYTE;
SHREE_ACTIVE : BYTE;
CURSCR : BYTE;
FONTNAME : ARRAY[0..LF_FACESIZE] OF BYTE;
FONTSIZE : LONGINT;
FONTATTR : BYTE;
FONTLAYOUT : BYTE;
ACTIVATIONKEY : BYTE;
HYPHENATION_ON : BYTE;
KEYBOARDNAME : ARRAY[0..12] OF BYTE;
END;

and similar java class

public class shreeRec {
public byte SHREE_ERROR;
public byte SHREE_ACTIVE;
public byte CURSCR;
public byte FONTNAME[];
public int FONTSIZE;
public byte FONTATTR;
public byte FONTLAYOUT;
public byte ACTIVATIONKEY;
public byte ACTIVATIONKEY_ON;
public byte KEYBOARDNAME[];
}
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't initialize your arrays. They remain null. What happens if you initialize them?
Also, I'm not that familiar with JNA, but shouldn't your class extend Structure or whatever the class is called?

I wasn't sure if Delphi's longint maps to Java's int. I'd have guessed long is a better match. I've checked and it has the same bounds, so that's a good choice after all.
 
Saurabh Bhandarkar
Greenhorn
Posts: 4
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Rob.

While using JNA we need to write an interface which declares all the functions in the dll & this interface extends the Library class of JNA.
I am able to call & execute other functions in dll using JNA...no problem about that.
I am stuck only at the Record-Class issue.
Also,I initialized the arrays & changed int to longint.But still the same exception is coming.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Prime wrote:Also, I'm not that familiar with JNA, but shouldn't your class extend Structure or whatever the class is called?


From the JNA docs of com.sun.jna.Structure:

Represents a native structure with a Java peer class. When used as a function parameter or return value, this class corresponds to struct*. When used as a field within another Structure, it corresponds to struct. The tagging interfaces Structure.ByReference and Structure.ByValue may be used to alter the default behavior.


So what happens if you let your shreeRec class extend Structure (and implement Structure.ByValue if needed)?
reply
    Bookmark Topic Watch Topic
  • New Topic