### Rust GUID Definition Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Shows the correct way to define GUIDs in Rust using the `DEFINE_GUID!` macro, ensuring proper formatting and zero-padding. ```Rust DEFINE_GUID!{GUID_DEVCLASS_SENSOR, 0x5175d334, 0xc371, 0x4806, 0xb3, 0xba, 0x71, 0xfd, 0x53, 0xc9, 0x25, 0x8d} ``` -------------------------------- ### COM Class Definition (C) Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Example of a COM class definition in C, as found in the SDK. This serves as a reference for the Rust binding. ```c class DECLSPEC_UUID("D9F6EE60-58C9-458B-88E1-2F908FD7F87C") SpDataKey; ``` -------------------------------- ### C Macro Constant Example Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Provides the original C macro definition for `CLSCTX_INPROC` which is used as a reference for Rust conversion. ```C #define CLSCTX_INPROC (CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) ``` -------------------------------- ### Rust Imports Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Demonstrates the correct way to import necessary types and modules from the winapi-rs crate, following alphabetical order. ```Rust use shared::basetsd::UINT64; use shared::minwindef::{BOOL, BYTE, INT, LPVOID, UINT}; use um::d3dcommon::{ D3D_CBUFFER_TYPE, D3D_FEATURE_LEVEL, D3D_INTERPOLATION_MODE, D3D_MIN_PRECISION, D3D_NAME, D3D_PARAMETER_FLAGS, D3D_PRIMITIVE, D3D_PRIMITIVE_TOPOLOGY, D3D_REGISTER_COMPONENT_TYPE, D3D_RESOURCE_RETURN_TYPE, D3D_SHADER_INPUT_TYPE, D3D_SHADER_VARIABLE_CLASS, D3D_SHADER_VARIABLE_TYPE, D3D_SRV_DIMENSION, D3D_TESSELLATOR_DOMAIN, D3D_TESSELLATOR_OUTPUT_PRIMITIVE, D3D_TESSELLATOR_PARTITIONING, ID3DBlob, }; ``` -------------------------------- ### Display Message Box using winapi Source: https://github.com/retep998/winapi-rs/blob/0.3/README.md Demonstrates how to display a message box on Windows using the `winapi` crate. It includes platform-specific logic for Windows and a fallback for other platforms. Requires the `winuser` feature. ```rust #[cfg(windows)] extern crate winapi; use std::io::Error; #[cfg(windows)] fn print_message(msg: &str) -> Result { 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 = 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(); } ``` -------------------------------- ### Cargo.toml Dependency for winapi Source: https://github.com/retep998/winapi-rs/blob/0.3/README.md Shows how to add the `winapi` crate as a dependency in `Cargo.toml`, specifically enabling the `winuser` feature for Windows-specific functionality. ```toml [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["winuser"] } ``` -------------------------------- ### Rust Function Pointers Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Illustrates the declaration of function pointers using the `FN!` macro for different calling conventions (stdcall, cdecl) and parameter types. ```Rust FN!{stdcall DRAWSTATEPROC( hdc: HDC, lData: LPARAM, wData: WPARAM, cx: c_int, cy: c_int, ) -> BOOL} FN!{stdcall NAMEENUMPROCA( LPSTR, LPARAM, ) -> BOOL} ``` -------------------------------- ### Rust Binding for D3D12_RESOURCE_BARRIER_u Union Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Demonstrates a Rust union binding for `D3D12_RESOURCE_BARRIER_u` which supports different storage sizes for 32-bit and 64-bit targets. ```Rust UNION!{union D3D12_RESOURCE_BARRIER_u { [u32; 4] [u64; 3], Transition Transition_mut: D3D12_RESOURCE_TRANSITION_BARRIER, Aliasing Aliasing_mut: D3D12_RESOURCE_ALIASING_BARRIER, UAV UAV_mut: D3D12_RESOURCE_UAV_BARRIER, }} ``` -------------------------------- ### COM Class Definition (Rust) Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md The equivalent COM class definition in Rust using the RIDL! macro, demonstrating how C definitions are translated. ```rust RIDL!{#[uuid(0xd9f6ee60, 0x58c9, 0x458b, 0x88, 0xe1, 0x2f, 0x90, 0x8f, 0xd7, 0xf8, 0x7c)] class SpDataKey;} ``` -------------------------------- ### Rust Extern Functions Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Shows how to declare external Windows API functions in Rust using the 'system' calling convention for stdcall functions, with one parameter per line. ```Rust extern "system" { pub fn GetProcessTimes( hProcess: HANDLE, lpCreationTime: LPFILETIME, lpExitTime: LPFILETIME, lpKernelTime: LPFILETIME, lpUserTime: LPFILETIME, ) -> BOOL; pub fn GetCurrentProcess() -> HANDLE; } ``` -------------------------------- ### Rust Binding for USN_RECORD_UNION Union Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Illustrates the Rust binding for a C union (`USN_RECORD_UNION`) that holds different versions of USN record headers, specifying the storage and member mappings. ```Rust UNION!{union USN_RECORD_UNION { [u64; 10], Header Header_mut: USN_RECORD_COMMON_HEADER, V2 V2_mut: USN_RECORD_V2, V3 V3_mut: USN_RECORD_V3, V4 V4_mut: USN_RECORD_V4, }} pub type PUSN_RECORD_UNION = *mut USN_RECORD_UNION; ``` -------------------------------- ### Rust Binding for USB_HUB_STATUS Struct with Bitfields Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Shows the Rust binding for `USB_HUB_STATUS`, which includes a union with a primitive field and an anonymous bitfield struct, mapping bitfields to methods. ```Rust STRUCT!{struct USB_HUB_STATUS { AsUshort16: USHORT, }} BITFIELD!{USB_HUB_STATUS AsUshort16: USHORT [ LocalPowerLost set_LocalPowerLost[0..1], OverCurrent set_OverCurrent[1..2], Reserved set_Reserved[2..16], ]} ``` -------------------------------- ### Rust Constant Definition Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Demonstrates the conversion of a C macro constant to a Rust constant, including type casting for bitwise operations. ```Rust pub const CLSCTX_INPROC: CLSCTX = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER; ``` -------------------------------- ### C++ Code for Determining Union Storage Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md A C++ utility function and macro to determine the required storage size and alignment for union types, useful for creating Rust bindings. ```C++ char const * type_for_alignment(uintptr_t align) { switch (align) { case 1: return "u8"; case 2: return "u16"; case 4: return "u32"; case 8: return "u64"; default: throw; } } #define PRINT_UNION(x) cout << "[" << type_for_alignment(alignof(x)) << "; " << sizeof(x) / alignof(x) << "]" << endl; int main() { PRINT_UNION(USN_RECORD_UNION); } ``` -------------------------------- ### APIDOC: IDWriteFontFileStream COM Interface Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Defines the `IDWriteFontFileStream` COM interface, including its UUID, inheritance from `IUnknown`, and its methods for file fragment reading, release, size retrieval, and last write time. ```APIDOC RIDL!{#[uuid(0x6d4865fe, 0x0ab8, 0x4d91, 0x8f, 0x62, 0x5d, 0xd6, 0xbe, 0x34, 0xa3, 0xe0)] interface IDWriteFontFileStream(IDWriteFontFileStreamVtbl): IUnknown(IUnknownVtbl) { fn ReadFileFragment( fragmentStart: *mut *const c_void, fileOffset: UINT64, fragmentSize: UINT64, fragmentContext: *mut *mut c_void, ) -> HRESULT, fn ReleaseFileFragment( fragmentContext: *mut c_void, ) -> (), fn GetFileSize( fileSize: *mut UINT64, ) -> HRESULT, fn GetLastWriteTime( lastWriteTime: *mut UINT64, ) -> HRESULT }} ``` -------------------------------- ### C Definition of USB_HUB_STATUS Union Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md The C definition of the `_USB_HUB_STATUS` union, containing a USHORT field and an anonymous struct with bitfields. ```C typedef union _USB_HUB_STATUS { USHORT AsUshort16; struct { USHORT LocalPowerLost:1; USHORT OverCurrent:1; USHORT Reserved:14; }; } USB_HUB_STATUS, *PUSB_HUB_STATUS; ``` -------------------------------- ### C Definition of USN_RECORD_UNION Union Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md The C definition of the `USN_RECORD_UNION`, showing its structure for holding various USN record types. ```C typedef union { USN_RECORD_COMMON_HEADER Header; USN_RECORD_V2 V2; USN_RECORD_V3 V3; USN_RECORD_V4 V4; } USN_RECORD_UNION, *PUSN_RECORD_UNION; ``` -------------------------------- ### C Definition of GROUP_AFFINITY Struct Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md The original C definition of the `_GROUP_AFFINITY` structure as found in the SDK. ```C typedef struct _GROUP_AFFINITY { KAFFINITY Mask; WORD Group; WORD Reserved[3]; } GROUP_AFFINITY, *PGROUP_AFFINITY; ``` -------------------------------- ### Rust Binding for GROUP_AFFINITY Struct Source: https://github.com/retep998/winapi-rs/blob/0.3/CONTRIBUTING.md Defines the Rust representation of the C `_GROUP_AFFINITY` struct, including its fields and a type alias for a pointer to it. ```Rust STRUCT!{struct GROUP_AFFINITY { Mask: KAFFINITY, Group: WORD, Reserved: [WORD; 3], }} pub type PGROUP_AFFINITY = *mut GROUP_AFFINITY; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.