Skip to content

dynamsoft-dbr/rust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dynamsoft Barcode Reader

crates.io version

FFI bindings to Dynamsoft Barcode Reader SDK.

License

Get the trial license.

Contact Us

https://www.dynamsoft.com/Company/Contact.aspx

Usage

Decode barcodes from an image file:

extern crate dbr;

use std::ffi::CStr;
use std::ffi::CString;
use std::os::raw::c_char;
use std::env;

use dbr::reader::*;

extern "C" fn callback(index: i32, barcode_type: *const c_char, barcode_value: *const c_char) {
    unsafe {
        println!(
            "Index {}, {}, {}",
            index,
            CStr::from_ptr(barcode_type).to_str().unwrap(),
            CStr::from_ptr(barcode_value).to_str().unwrap()
        );
    }
}

fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() == 1 {
        println!("Please input an image file.");
        return
    }

    println!("Hello Dynamsoft Barcode Reader!");
    unsafe {
        register_callback(Some(callback));
        let image_file = CString::new(env::args().nth(1).expect("Missing argument")).unwrap();
        let license = CString::new("t0068NQAAAFKYHV9xSZDEThUtClXNzxXH9TLSj/vYcY8mSKa0RxaGw3qNynyAMJ9Ib8UPxzFsbAMIugqPO313BvfiOdmZFTY=").unwrap();
        c_decodeFile(image_file.as_ptr(), license.as_ptr());
    }

    println!("Bye!");
}

Rust barcode reader

How to Customize the Package

  1. Install Dynamsoft Barcode Reader.

  2. Get the source code;

  3. Copy Dynamsoft\Barcode Reader <version number>\Components\C_C++\Redist\x64\DynamsoftBarcodeReaderx64.dll to platforms\win\DynamsoftBarcodeReaderx64.dll.

    Copy Dynamsoft\Barcode Reader <version number>\Components\C_C++\Lib\DBRx64.lib to platforms\win\DBRx64.lib

  4. Add function definitions to reader.h and add function implementations to reader.c.

  5. Generate reader.rs with bindgen.

    cargo install bindgen
    cd src
    bindgen reader.h -o reader.rs
  6. Add the local package to your Rust project:

    [dependencies]
    dbr = { path = "../dbr" }

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published