Crates.io | dbr |
lib.rs | dbr |
version | 0.1.3 |
source | src |
created_at | 2018-10-16 08:35:46.834941 |
updated_at | 2018-10-16 12:37:30.338255 |
description | Dynamsoft's Barcode Reader SDK enables you to efficiently embed barcode reading functionality in your web, desktop or mobile application using just a few lines of code. |
homepage | https://www.dynamsoft.com/Products/Dynamic-Barcode-Reader.aspx |
repository | https://github.com/dynamsoft-dbr/rust |
max_upload_size | |
id | 90930 |
size | 6,214,562 |
FFI bindings to Dynamsoft Barcode Reader SDK.
Get the trial license.
https://www.dynamsoft.com/Company/Contact.aspx
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!");
}
Install Dynamsoft Barcode Reader.
Get the source code;
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
Add function definitions to reader.h
and add function implementations to reader.c
.
Generate reader.rs
with bindgen.
cargo install bindgen
cd src
bindgen reader.h -o reader.rs
Add the local package to your Rust project:
[dependencies]
dbr = { path = "../dbr" }