Alain-Pierre BRUNEL wrote:
> Hi, I use a native SDK written in C from a Java code (thanks to JNI).
> An issue I have is that the C API contains some constants and enum
> structs.
> I have to redefine these constants on the Java side, because I don't
> know how to import these "enum" & "#define".
> It makes a coherence issue between the C Headers & the Java const.
> If the C Headers constants values change, I've to change the Java
> classes.
>
> Do you know a way to import native defined constants into Java code ?
The best way I know of is to use some sort of intermediate form to
represent these values that you can easily parse (XML, or a simple
properties file can work well for this, but whatever you're happy
parsing will work). Then create a script or program that will take this
data and construct a .h file and a .java file at the beginning of your
build process.
Thus, if your data file contains:
VALUE1 = 10
VALUE2 = 15
VALUE3 = 30
...it would generate a .h file with:
#define VALUE1 = 10
#define VALUE2 = 15
#define VALUE3 = 30
...and a Java file with:
public static final int VALUE1 = 10;
public static final int VALUE2 = 15
public static final int VALUE3 = 30
If you keep these elements in their own .h/.java files and import them
as necessary into other files, then you can make them completely dynamic
in this manner.
HTH!
Brad BARCLAY
--
=-=-=-=-=-=-=-=-=
From the OS/2 WARP v4.5 Desktop of Brad BARCLAY.
The jSyncManager Project:
http://www.jsyncmanager.org