文件
官方通信渠道:#生鏽社區不和諧的Windows-dev
該板條箱為所有Windows API提供了RAW FFI綁定。它們是使用Microsoft的Windows 10 SDK手工收集的。我的目標是通過“擁抱,擴展和滅絕”技術用該板條箱中其他板條箱中的所有現有Windows FFI替換。
如果此板條箱缺少您需要的東西,請隨時創建問題,打開拉動請求或通過其他方式與我聯繫。
該板條箱取決於生鏽1.6或窗戶上的較新。在其他平台上,這個板條箱是一個毫無疑問的,應該用Rust 1.2或更新的生鏽編譯。
使用std::mem::zeroed()創建一個聯合實例,然後使用其中一種變體方法分配您想要的值。
每個模塊都在功能標誌上登機,因此您必須啟用適當的功能才能訪問這些項目。例如,如果您想使用winapi::um::winuser中的東西,則必須啟用winuser功能。
您可以使用文檔中的搜索功能查找定義項目的位置。
這個板條箱無非是與Windows API的原始綁定。如果您想知道如何使用Windows API中的各種功能,則可以查找MSDN上的各種項目,其中包含詳細的文檔。
no_std項目中使用此庫嗎?是的,絕對!默認情況下, winapi的std功能被禁用,使您可以使用core和winapi編寫Windows應用程序。
winapi的HANDLE與std的HANDLE不兼容?因為默認情況下winapi不依賴於std ,因此必須定義c_void本身,而不是使用std::os::raw::c_void 。但是,如果您啟用winapi的std功能,則它將從std重新啟用c_void ,並導致winapi的HANDLE與std的HANDLE相同。
-sys板條箱,例如kernel32-sys嗎?否。這些板條箱是winapi 0.2組織方式的遺產。從winapi開始,所有定義都直接在winapi本身中,因此不再需要使用這些-sys板條箱。
CARGO.TOML:
[ target . 'cfg(windows)' . dependencies ]
winapi = { version = " 0.3 " , features = [ " winuser " ] }main.rs:
# [ cfg ( windows ) ] extern crate winapi ;
use std :: io :: Error ;
# [ cfg ( windows ) ]
fn print_message ( msg : & str ) -> Result < i32 , Error > {
use std :: ffi :: OsStr ;
use std :: iter :: once ;
use std :: os :: windows :: ffi :: OsStrExt ;
use std :: ptr :: null_mut ;
use winapi :: um :: winuser :: { MB_OK , MessageBoxW } ;
let wide : Vec < u16 > = OsStr :: new ( msg ) . encode_wide ( ) . chain ( once ( 0 ) ) . collect ( ) ;
let ret = unsafe {
MessageBoxW ( null_mut ( ) , wide . as_ptr ( ) , wide . as_ptr ( ) , MB_OK )
} ;
if ret == 0 { Err ( Error :: last_os_error ( ) ) }
else { Ok ( ret ) }
}
# [ cfg ( not ( windows ) ) ]
fn print_message ( msg : & str ) -> Result < ( ) , Error > {
println ! ( "{}" , msg ) ;
Ok ( ( ) )
}
fn main ( ) {
print_message ( "Hello, world!" ) . unwrap ( ) ;
} 您在項目中使用winapi嗎?如果是這樣,您可能有興趣在Patreon上為我提供財務支持。特別是鼓勵公司捐贈的公司(我在看著您的Microsoft)。