JNA和ZBar(条码阅读器库)

发布于 2024-08-24 21:49:03 字数 839 浏览 1 评论 0 原文

我正在使用 JNAZBar(条形码阅读器库)

在JNA中,需要声明C中的结构体。例如::

// In C
typedef struct {
    char* id;
    char* name;
    int age;
    char* sectionId
} EMPLOYEE;

to

// In Java with JNA
public static class Employee extends Structure {  // com.sun.jna.Structure
    String id;
    String name;
    int age;
    String sectionId;
}

但是在ZBar中,结构体没有成员。例如::

// zbar-0.10/include/zbar.h
// line:1009-1011
struct zbar_image_scanner_s;
/** opaque image scanner object. */
typedef struct zbar_image_scanner_s zbar_image_scanner_t;

没有声明结构的大小或成员。

如何在 JNA 中为这些结构编写接口?

I'm creating Java Interface with JNA for ZBar(library for bar code reader).

In JNA, structures in C are needed to declare. For example::

// In C
typedef struct {
    char* id;
    char* name;
    int age;
    char* sectionId
} EMPLOYEE;

to

// In Java with JNA
public static class Employee extends Structure {  // com.sun.jna.Structure
    String id;
    String name;
    int age;
    String sectionId;
}

But in ZBar, structures have no members. For example::

// zbar-0.10/include/zbar.h
// line:1009-1011
struct zbar_image_scanner_s;
/** opaque image scanner object. */
typedef struct zbar_image_scanner_s zbar_image_scanner_t;

That doesn't declare size or members of the structures.

How can I write interfaces for these structures in JNA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-08-31 21:49:39

由于结构是不透明的,API 不需要了解其内容,因此您无需担心它们。

每当您看到对“zbar_image_scanner_t *”的引用时,只需使用指针即可。

Since the structures are opaque, the API can not require any knowledge of their contents, and so you don't need to worry about them.

Just use Pointer whenever you see a reference to "zbar_image_scanner_t *".

古镇旧梦 2024-08-31 21:49:31

struct zbar_image_scanner_s 在 img_scanner.c 中声明为:

/* image scanner state */
struct zbar_image_scanner_s {
    zbar_scanner_t *scn;        /* associated linear intensity scanner */
    zbar_decoder_t *dcode;      /* associated symbol decoder */
#ifdef ENABLE_QRCODE
    qr_reader *qr;              /* QR Code 2D reader */
#endif

    const void *userdata;       /* application data */
    /* user result callback */
    zbar_image_data_handler_t *handler;

    unsigned long time;         /* scan start time */
    zbar_image_t *img;          /* currently scanning image *root* */
    int dx, dy, du, umin, v;    /* current scan direction */
    zbar_symbol_set_t *syms;    /* previous decode results */
    /* recycled symbols in 4^n size buckets */
    recycle_bucket_t recycle[RECYCLE_BUCKETS];

    int enable_cache;           /* current result cache state */
    zbar_symbol_t *cache;       /* inter-image result cache entries */

    /* configuration settings */
    unsigned config;            /* config flags */
    int configs[NUM_SCN_CFGS];  /* int valued configurations */

#ifndef NO_STATS
    int stat_syms_new;
    int stat_iscn_syms_inuse, stat_iscn_syms_recycle;
    int stat_img_syms_inuse, stat_img_syms_recycle;
    int stat_sym_new;
    int stat_sym_recycle[RECYCLE_BUCKETS];
#endif
};

不知道编译的设置(即:ENABLE_QRCODE、NO_STATS 等)是什么;我将把 c 到 jna 结构的转换留给您,但映射规则如 https://jna.dev.java.net/javadoc/overview-summary.html 应该适用于它。

the struct zbar_image_scanner_s is declared in img_scanner.c as:

/* image scanner state */
struct zbar_image_scanner_s {
    zbar_scanner_t *scn;        /* associated linear intensity scanner */
    zbar_decoder_t *dcode;      /* associated symbol decoder */
#ifdef ENABLE_QRCODE
    qr_reader *qr;              /* QR Code 2D reader */
#endif

    const void *userdata;       /* application data */
    /* user result callback */
    zbar_image_data_handler_t *handler;

    unsigned long time;         /* scan start time */
    zbar_image_t *img;          /* currently scanning image *root* */
    int dx, dy, du, umin, v;    /* current scan direction */
    zbar_symbol_set_t *syms;    /* previous decode results */
    /* recycled symbols in 4^n size buckets */
    recycle_bucket_t recycle[RECYCLE_BUCKETS];

    int enable_cache;           /* current result cache state */
    zbar_symbol_t *cache;       /* inter-image result cache entries */

    /* configuration settings */
    unsigned config;            /* config flags */
    int configs[NUM_SCN_CFGS];  /* int valued configurations */

#ifndef NO_STATS
    int stat_syms_new;
    int stat_iscn_syms_inuse, stat_iscn_syms_recycle;
    int stat_img_syms_inuse, stat_img_syms_recycle;
    int stat_sym_new;
    int stat_sym_recycle[RECYCLE_BUCKETS];
#endif
};

not knowing what your setup (ie: ENABLE_QRCODE, NO_STATS, etc) for compilation is; I will leave the c to jna structure conversion to you, but the mapping rules as desccribe in https://jna.dev.java.net/javadoc/overview-summary.html should apply to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文