【win11 x64 】Why is my output incorrect or even all 0?

27 views
Skip to first unread message

twj TWJ

unread,
Nov 14, 2024, 2:39:22 AM11/14/24
to Java Native Access
thanks,I encountered a very tricky problem. The result I got when calling DLL with JNA in Java was completely different from the result when calling with VS, and even the output of Java could be considered empty because all the results were 0.Here is my code. The count_out in Java is 1, but the output from 1 to 15 in the pout happens to have 0 bytes for SPECIAL_ROOT

/*************************************** .h ******************************* */
LIB void function(
    unsigned long long cf, unsigned long sm, unsigned long bd, unsigned long len, short* data, int state, //输如参数
    unsigned int& count_Out,//输出数量
    RESULT*& pout           //输出数据对应输出数量
);


typedef struct
{
    unsigned char data_type;
    SPECIAL_RESULT special_result;
}RESULT;

typedef struct
{
    uint8_t     type;      
    int64_t     s_cf;      
    uint32_t    s_bw;        
    uint8_t     s_demo;      
}SPECIAL_RESULT;

/********************************************* java ************************************** */

@Data
@EqualsAndHashCode(callSuper=true)
@Structure.FieldOrder({"data_type","special_result"})
public class RESULT extends Structure {

    public byte data_type;

    public SpecialResult special_result;

    public OtherResult other_result;

    public static class ByReference extends RESULT implements Structure.ByReference {

    }

    public RESULT() {
        super(ALIGN_NONE);
    }
}

@Data
@EqualsAndHashCode(callSuper=true)
@Structure.FieldOrder({"type", "s_cf", "s_bw", "s_demo"})
public class SpecialResult extends Structure {

  public  byte type;
  public  long s_cf;
  public  int s_bw;
  public  byte s_demo;

  public SpecialResult() {
    super(ALIGN_NONE);
  }

}

  void NarrowBandSort(long cf,NativeLong sm, NativeLong bd, NativeLong len, short[] data, int state, IntByReference count_Out, PointerByReference pout);

Matthias Bläsing

unread,
Nov 14, 2024, 2:27:44 PM11/14/24
to jna-...@googlegroups.com
Hi,

1. Question: How do you call the function?
2. Question: Why do you set ALIGN_NONE? I don't see a prama in the header, so no indicator for this.

Greetings

Matthias
--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jna-users/e435ba85-23ea-4ff5-ae75-1fbb8f59b06an%40googlegroups.com.

Daniel B. Widdis

unread,
Nov 19, 2024, 4:22:53 PM11/19/24
to jna-...@googlegroups.com
Matthias's suggestion about alignment is probably the first thing to check.  If that doesn't work...
 
The count_out in Java is 1, but the output from 1 to 15 in the pout happens to have 0

I'm not sure what you mean by "the output from 1 to 15".  Is that bytes or array indices?   Is count_out the number of bytes or number of structures? 

The data type RESULT*& pout implies you'd extract a pointer from pout and then use that pointer in a constructor for SPECIAL_RESULT that reads the bytes; I don't see such a constructor.





--
Dan Widdis
Reply all
Reply to author
Forward
0 new messages