我最近发现了windows-rs框架,并一直在寻求通过实现其ICredentialProvider COM 接口来在 Rust 中构建Windows 凭据提供程序。
我一直在使用现有问题之一中汇总的信息进行概念验证实现,但我不确定如何实际将编译后的 Rust 公开为正确的 DLL,然后向 Windows 系统注册。
use std::cell::RefCell;
use windows::{
core::implement,
Win32::UI::Shell::{ICredentialProvider, ICredentialProvider_Impl},
};
fn main() -> windows::core::Result<()> {
#[implement(ICredentialProvider)]
struct Provider {
mutable_state: RefCell<u32>,
}
impl Provider {
fn new() -> Self {
Self {
mutable_state: RefCell::new(0),
}
}
}
impl ICredentialProvider_Impl for Provider {
fn Advise(
&self,
pcpe: &core::option::Option<windows::Win32::UI::Shell::ICredentialProviderEvents>,
upadvisecontext: usize,
) -> windows::core::Result<()> {
*self.mutable_state.borrow_mut() = 42;
todo!();
}
fn GetCredentialAt(
&self,
dwindex: u32,
) …Run Code Online (Sandbox Code Playgroud)