UNICODE is defined should not be included. It is the user's responsibility to explicitly choose between W and A functions (and they should always choose W).RIDL!).type would turn into type_.{}. Macro invocations at the expression level should use ().winapi-rs is 99, and is strictly enforced.: used for inheritance in COM interfaces, which should remain at the end of the previous line.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, };
system for stdcall and C for cdecl (and fastcall for those couple of fastcall functions out there).extern "system" { pub fn GetProcessTimes( hProcess: HANDLE, lpCreationTime: LPFILETIME, lpExitTime: LPFILETIME, lpKernelTime: LPFILETIME, lpUserTime: LPFILETIME, ) -> BOOL; pub fn GetCurrentProcess() -> HANDLE; }
#[inline].BOOLEAN into bool, and so on.FN!{stdcall DRAWSTATEPROC( hdc: HDC, lData: LPARAM, wData: WPARAM, cx: c_int, cy: c_int, ) -> BOOL} FN!{stdcall NAMEENUMPROCA( LPSTR, LPARAM, ) -> BOOL}
-1i16 as u16. Use the primitive integer types that correspond to the type of the constant.-1isize as LPFOO.The C version found in the SDK:
#define CLSCTX_INPROC (CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER)
And what the Rust binding should look like:
pub const CLSCTX_INPROC: CLSCTX = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER;
DEFINE_GUID!{GUID_DEVCLASS_SENSOR, 0x5175d334, 0xc371, 0x4806, 0xb3, 0xba, 0x71, 0xfd, 0x53, 0xc9, 0x25, 0x8d}
Each field must be on its own line.
The C version found in the SDK:
typedef struct _GROUP_AFFINITY { KAFFINITY Mask; WORD Group; WORD Reserved[3]; } GROUP_AFFINITY, *PGROUP_AFFINITY;
And what the Rust binding should look like:
STRUCT!{struct GROUP_AFFINITY { Mask: KAFFINITY, Group: WORD, Reserved: [WORD; 3], }} pub type PGROUP_AFFINITY = *mut GROUP_AFFINITY;
The C version found in the SDK:
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;
And what the Rust binding should look like:
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;
UNION! is the storage for that union. It must have both the correct size and alignment. You can use the following C++ code to print out the storage for any union type that can be named. You may need to use a combination of #define NONAMELESSUNION and decltype in order to name anonymous unions.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); }
UNION! allows a second storage to be specified, the first for 32bit and the second for 64bit.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, }}
FOO contains a single anonymous struct or union, give the anonymous struct or union a name of FOO_s or FOO_u respectively, and the field a name of s or u respectively.FOO contains multiple anonymous structs or unions, append a number, such as s1: FOO_s1 s2: FOO_s2 or u1: FOO_u1 u2: FOO_u2.Bar, but still contains an anonymous struct or union then retain the name of Bar for the field and name the anonymous struct or union after the field, such as FOO_Bar.The C version found in the SDK:
typedef union _USB_HUB_STATUS { USHORT AsUshort16; struct { USHORT LocalPowerLost:1; USHORT OverCurrent:1; USHORT Reserved:14; }; } USB_HUB_STATUS, *PUSB_HUB_STATUS;
And what the Rust binding should look like:
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], ]}
Foo, then name them Foo_1 and Foo_2. In addition, overloaded methods must appear in reverse order to comply with the COM binary interface. See #523 for more details.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 }}
The C version found in the SDK:
class DECLSPEC_UUID("D9F6EE60-58C9-458B-88E1-2F908FD7F87C") SpDataKey;
And what the Rust binding should look like:
RIDL!{#[uuid(0xd9f6ee60, 0x58c9, 0x458b, 0x88, 0xe1, 0x2f, 0x90, 0x8f, 0xd7, 0xf8, 0x7c)] class SpDataKey;}
src/winrt is special and has its own namespaced organization.