Crates.io | windows-dll |
lib.rs | windows-dll |
version | 0.4.1 |
source | src |
created_at | 2020-04-20 16:47:21.993676 |
updated_at | 2022-06-23 18:42:01.951736 |
description | Macro for dynamically loading windows dll functions |
homepage | https://github.com/thisKai/rust-windows-dll |
repository | https://github.com/thisKai/rust-windows-dll |
max_upload_size | |
id | 232265 |
size | 66,885 |
Macro for dynamically loading windows dll functions
use {
windows_dll::dll,
winapi::shared::{
minwindef::ULONG,
ntdef::{NTSTATUS, NT_SUCCESS, WCHAR},
},
};
#[allow(non_snake_case)]
#[repr(C)]
struct OSVERSIONINFOW {
dwOSVersionInfoSize: ULONG,
dwMajorVersion: ULONG,
dwMinorVersion: ULONG,
dwBuildNumber: ULONG,
dwPlatformId: ULONG,
szCSDVersion: [WCHAR; 128],
}
#[dll(ntdll)]
extern "system" {
#[allow(non_snake_case)]
fn RtlGetVersion(lpVersionInformation: *mut OSVERSIONINFOW) -> NTSTATUS;
}
fn os_version_info() -> OSVERSIONINFOW {
unsafe {
let mut vi = OSVERSIONINFOW {
dwOSVersionInfoSize: 0,
dwMajorVersion: 0,
dwMinorVersion: 0,
dwBuildNumber: 0,
dwPlatformId: 0,
szCSDVersion: [0; 128],
};
let status = RtlGetVersion(&mut vi as _);
if NT_SUCCESS(status) {
vi
} else {
panic!()
}
}
}
#[dll(ntdll)]
extern "system" {
#[allow(non_snake_case)]
#[fallible]
fn RtlGetVersion(lpVersionInformation: *mut OSVERSIONINFOW) -> NTSTATUS;
}
fn os_version_info() -> Result<OSVERSIONINFOW, windows_dll::Error> {
unsafe {
let mut vi = OSVERSIONINFOW {
dwOSVersionInfoSize: 0,
dwMajorVersion: 0,
dwMinorVersion: 0,
dwBuildNumber: 0,
dwPlatformId: 0,
szCSDVersion: [0; 128],
};
let status = RtlGetVersion(&mut vi as _)?;
if NT_SUCCESS(status) {
Ok(vi)
} else {
panic!()
}
}
}
#[dll(ntdll)]
extern "system" {
#[link_name = "RtlGetVersion"]
fn rtl_get_version(lp_version_information: *mut OSVERSIONINFOW) -> NTSTATUS;
}
#[dll(uxtheme)]
extern "system" {
#[link_ordinal = 133]
fn allow_dark_mode_for_window(hwnd: HWND, allow: BOOL) -> BOOL;
}
#[dll(ntdll)]
extern "system" {
#[link_name = "RtlGetVersion"]
fn rtl_get_version(lp_version_information: *mut OSVERSIONINFOW) -> NTSTATUS;
}
unsafe fn rtl_get_version_exists() -> bool {
rtl_get_version::exists()
}
use windows_dll::*;
#[dll(ntdll, LOAD_LIBRARY_SEARCH_SYSTEM32)]
extern "system" {
#[link_name = "RtlGetVersion"]
fn rtl_get_version(lp_version_information: *mut OSVERSIONINFOW) -> NTSTATUS;
}