What kind of typedef from C is in Java? Or how can you get around this? For example, I work with Android-NDK, in C there is a function, its prototype:

LONG List_File_Card(SCARDHANDLE gCardHandle, BYTE *buffer, DWORD *bufferLength); 

The types LONG,SCARDHANDLE,BYTE,DWORD defined in h-nicks, by analogy typedef long LONG;

In Java code, I define the same function as

 public static native LONG List_File_Card(SCARDHANDLE gCardHandle, BYTE *buffer, DWORD *bufferLength); 

It is necessary that the same data type names be received and returned to this function as in C. How can they be better defined in Java? Using classes, interfaces, enum? Tell me please.

  • why bother to redefine your types? do you rewrite the program in java? - Senior Pomidor
  • @Senior Pomidor, you need to make an interface in Java, Java functions will be called, and processed in C. It is desirable that the same data types are used in Java as in the C code, but this is impossible for a campaign .. so he asked - VadoM
  • To do this, use other mechanisms. look towards JSON. Let the program produce the result as JSON, if possible. - Senior Pomidor

2 answers 2

Dear sir, you have a problem not in typedef , but in the mapping of sishnyh types into Java types:

Read to dock about a mapping of sishnyh types on Java.

On the C side, you must declare a function like:

 jlong <имя_пакета>_List_File_Card(<blah-blah); 
  • Your answer sent me in the right direction, thanks! But since I am generally a novice, I would not refuse a detailed example) - VadoM

typedef , or similar, in Java is not.


You can try to make emulation through inheritance:

 public class LONG extends Long {} 

But it will not be a primitive type, so I think you should not do it.