зеркало из https://github.com/microsoft/dia-rs.git
0.4 (#10)
This commit is contained in:
Родитель
38da3d5602
Коммит
12fd3c319b
|
@ -16,7 +16,7 @@ features = [
|
|||
]
|
||||
|
||||
[dependencies.microsoft-dia]
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
```
|
||||
|
||||
Make use of any DIA SDK APIs as needed.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "microsoft-dia"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
authors = ["Microsoft"]
|
||||
edition = "2018"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
@ -18,11 +18,9 @@ members = [
|
|||
[dependencies.windows]
|
||||
version = "0.43.0"
|
||||
features = [
|
||||
"implement",
|
||||
"Win32_Foundation",
|
||||
"Win32_System_LibraryLoader",
|
||||
"Win32_System_Com_StructuredStorage",
|
||||
"Win32_System_Ole"
|
||||
]
|
||||
|
||||
[features]
|
||||
implement = []
|
|
@ -7,13 +7,25 @@ use windows::{
|
|||
fn main() -> windows::core::Result<()> {
|
||||
unsafe {
|
||||
CoInitializeEx(None, COINIT_MULTITHREADED)?;
|
||||
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(s!("msdia140.dll"), &DiaSource)?;
|
||||
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(
|
||||
s!(
|
||||
r#"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll"#
|
||||
),
|
||||
&DiaSource,
|
||||
)?;
|
||||
let executable = std::env::current_exe().unwrap();
|
||||
source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?;
|
||||
let session = source.openSession()?;
|
||||
let symbols = session.globalScope()?.findChildren(SymTagFunction, w!("sample_functions::*"), nsfRegularExpression.0 as u32)?;
|
||||
let symbols = session.globalScope()?.findChildren(
|
||||
SymTagFunction,
|
||||
w!("sample_functions::*"),
|
||||
nsfRegularExpression.0 as u32,
|
||||
)?;
|
||||
|
||||
println!("Function symbols found in sample_functions::* ({}):", &executable.to_string_lossy());
|
||||
println!(
|
||||
"Function symbols found in sample_functions::* ({}):",
|
||||
&executable.to_string_lossy()
|
||||
);
|
||||
|
||||
for i in 0..symbols.Count()? {
|
||||
println!("\t{}", symbols.Item(i as u32)?.name()?);
|
||||
|
|
|
@ -1,56 +1,27 @@
|
|||
use std::io::Write;
|
||||
use windows_metadata::reader::{File, Reader, Tree};
|
||||
use std::{fs, path::PathBuf, process::Command};
|
||||
use windows_metadata::reader::File;
|
||||
|
||||
fn main() {
|
||||
let start = std::time::Instant::now();
|
||||
let mut output_path = std::path::PathBuf::from("");
|
||||
let files = [
|
||||
File::new(".windows/winmd/Microsoft.Dia.winmd").unwrap(),
|
||||
File::new(".windows/winmd/Windows.Win32.winmd").unwrap(),
|
||||
File::new(".windows/winmd/Windows.Win32.Interop.winmd").unwrap(),
|
||||
];
|
||||
|
||||
output_path.push("src/Microsoft");
|
||||
let _ = std::fs::remove_dir_all(&output_path);
|
||||
output_path.pop();
|
||||
|
||||
let winmd_files = [File::new(".windows/winmd/Microsoft.Dia.winmd").unwrap(), File::new(".windows/winmd/Windows.Win32.winmd").unwrap(), File::new(".windows/winmd/Windows.Win32.Interop.winmd").unwrap()];
|
||||
let reader = Reader::new(&winmd_files);
|
||||
let root = reader.tree("Microsoft", &[]).expect("Microsoft namespace not found");
|
||||
|
||||
let trees = root.flatten();
|
||||
trees.iter().for_each(|tree| gen_tree(&reader, &output_path, tree));
|
||||
|
||||
output_path.pop();
|
||||
println!("Elapsed: {} ms", start.elapsed().as_millis());
|
||||
}
|
||||
|
||||
fn gen_tree(reader: &Reader, output: &std::path::Path, tree: &Tree) {
|
||||
let mut path = std::path::PathBuf::from(output);
|
||||
|
||||
path.push(tree.namespace.replace('.', "/"));
|
||||
std::fs::create_dir_all(&path).unwrap();
|
||||
|
||||
let mut gen = windows_bindgen::Gen::new(reader);
|
||||
gen.namespace = tree.namespace;
|
||||
gen.cfg = false;
|
||||
|
||||
let mut tokens = windows_bindgen::namespace(&gen, tree);
|
||||
tokens.push_str(r#"#[cfg(feature = "implement")] ::core::include!("impl.rs");"#);
|
||||
fmt_tokens(tree.namespace, &mut tokens);
|
||||
std::fs::write(path.join("mod.rs"), tokens).unwrap();
|
||||
|
||||
let mut tokens = windows_bindgen::namespace_impl(&gen, tree);
|
||||
fmt_tokens(tree.namespace, &mut tokens);
|
||||
std::fs::write(path.join("impl.rs"), tokens).unwrap();
|
||||
}
|
||||
|
||||
fn fmt_tokens(namespace: &str, tokens: &mut String) {
|
||||
let mut child = std::process::Command::new("rustfmt").stdin(std::process::Stdio::piped()).stdout(std::process::Stdio::piped()).stderr(std::process::Stdio::null()).spawn().expect("Failed to spawn `rustfmt`");
|
||||
|
||||
let mut stdin = child.stdin.take().expect("Failed to open stdin");
|
||||
stdin.write_all(tokens.as_bytes()).unwrap();
|
||||
drop(stdin);
|
||||
let output = child.wait_with_output().unwrap();
|
||||
|
||||
if output.status.success() {
|
||||
*tokens = String::from_utf8(output.stdout).expect("Failed to parse UTF-8");
|
||||
} else {
|
||||
println!("** {} - rustfmt failed", namespace);
|
||||
let output_path = PathBuf::from("src/bindings.rs");
|
||||
if output_path.exists() {
|
||||
fs::remove_file(&output_path).unwrap();
|
||||
}
|
||||
fs::write(
|
||||
&output_path,
|
||||
windows_bindgen::component("Microsoft.Dia", &files),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut child = Command::new("rustfmt")
|
||||
.args([&output_path])
|
||||
.spawn()
|
||||
.expect("Failed to start rustfmt");
|
||||
|
||||
child.wait().expect("rustfmt failed");
|
||||
}
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
newline_style = "Unix"
|
||||
max_width = 500
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
18989
src/Microsoft/Dia/mod.rs
18989
src/Microsoft/Dia/mod.rs
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1 +0,0 @@
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
#![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, clashing_extern_declarations, unused_variables, dead_code, clippy::all)]
|
||||
pub mod Dia;
|
||||
#[cfg(feature = "implement")]
|
||||
::core::include!("impl.rs");
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -7,7 +7,8 @@ use windows::Win32::{
|
|||
System::LibraryLoader::{GetProcAddress, LoadLibraryExA, LOAD_WITH_ALTERED_SEARCH_PATH},
|
||||
};
|
||||
|
||||
type DllGetClassObject = unsafe extern "system" fn(*const GUID, *const GUID, *mut *mut std::ffi::c_void) -> HRESULT;
|
||||
type DllGetClassObject =
|
||||
unsafe extern "system" fn(*const GUID, *const GUID, *mut *mut std::ffi::c_void) -> HRESULT;
|
||||
|
||||
/// Creates a single object of a class associated with a specified CLSID
|
||||
/// present in the specified dynamic-link library-based COM server.
|
||||
|
@ -22,7 +23,13 @@ pub unsafe fn NoRegCoCreate<T: Interface>(lib: PCSTR, rclsid: *const GUID) -> Re
|
|||
if let Some(farproc) = GetProcAddress(instance, s!("DllGetClassObject")) {
|
||||
let get_class_object: DllGetClassObject = std::mem::transmute(farproc);
|
||||
let mut factory: Option<IClassFactory> = None;
|
||||
if get_class_object(rclsid, &IClassFactory::IID, &mut factory as *mut _ as *mut _).is_ok() {
|
||||
if get_class_object(
|
||||
rclsid,
|
||||
&IClassFactory::IID,
|
||||
&mut factory as *mut _ as *mut _,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
return factory.unwrap().CreateInstance(None);
|
||||
}
|
||||
}
|
16
src/lib.rs
16
src/lib.rs
|
@ -4,7 +4,15 @@ extern crate windows;
|
|||
|
||||
pub mod helpers;
|
||||
|
||||
#[allow(non_camel_case_types, non_snake_case, non_upper_case_globals, clippy::derivable_impls, clippy::missing_safety_doc, clippy::too_many_arguments)]
|
||||
mod Microsoft;
|
||||
|
||||
pub use Microsoft::Dia::*;
|
||||
#[allow(
|
||||
non_camel_case_types,
|
||||
non_snake_case,
|
||||
non_upper_case_globals,
|
||||
clippy::useless_transmute,
|
||||
clippy::extra_unused_lifetimes,
|
||||
clippy::derivable_impls,
|
||||
clippy::missing_safety_doc,
|
||||
clippy::too_many_arguments
|
||||
)]
|
||||
pub mod bindings;
|
||||
pub use bindings::*;
|
||||
|
|
Загрузка…
Ссылка в новой задаче