Skip to content

Commit

Permalink
dynamic load of open and close api
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Dec 8, 2024
1 parent 3d7f4e7 commit 2b222c1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
25 changes: 18 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/samples/simple/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ description = "Example of using the generated MsQuic binding from winmd"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libloading = "0.8"
"msquic-sys" = { version = "*", path = "../../libs/msquic-sys", features = ["MsQuic"]}
"windows-core" = "0.57.0"
"windows-core" = "0.57.0"
24 changes: 24 additions & 0 deletions crates/samples/simple/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,27 @@ mod tests {
api.registation_close(rh);
}
}

#[cfg(test)]
mod test2 {
use msquic_sys::Microsoft::MsQuic::{QUIC_API_TABLE, QUIC_API_VERSION_2};

#[test]
fn dynamic_load() {
let lib_name = libloading::library_filename("msquic");
let lib = unsafe { libloading::Library::new(lib_name) }.unwrap();
let fn_open: libloading::Symbol<
unsafe extern "C" fn(u32, *mut *mut QUIC_API_TABLE) -> i32,
> = unsafe { lib.get(b"MsQuicOpenVersion") }.unwrap();
let fn_close: libloading::Symbol<unsafe extern "C" fn(*const QUIC_API_TABLE)> =
unsafe { lib.get(b"MsQuicClose") }.unwrap();
let mut api = std::ptr::null_mut::<QUIC_API_TABLE>();
let ec = unsafe { fn_open(QUIC_API_VERSION_2, std::ptr::addr_of_mut!(api)) };
assert_eq!(
ec,
msquic_sys::Microsoft::MsQuic::Win32::QUIC_STATUS_SUCCESS.0
);
assert!(!api.is_null());
unsafe { fn_close(api) };
}
}

0 comments on commit 2b222c1

Please sign in to comment.