Skip to content

Instantly share code, notes, and snippets.

View kennykerr's full-sized avatar

Kenny Kerr kennykerr

View GitHub Profile
use super::*;
#[derive(Default)]
pub struct Gen<'a> {
pub namespace: &'a str,
pub sys: bool,
pub flatten: bool,
pub cfg: bool,
pub doc: bool,
pub min_enum: bool,
use std::io::prelude::*;
fn main() {
let mut file = std::fs::File::create(r#"C:\git\check_all.cmd"#).unwrap();
let reader = reader::TypeReader::get_mut();
let root = reader.types.get_namespace("Windows").unwrap();
write_features(&mut file, root.namespace, root)
}
AI = []
AI_MachineLearning = ["AI", "Foundation", "Foundation_Collections"]
AI_MachineLearning_Preview = ["AI_MachineLearning", "Foundation_Collections"]
ApplicationModel = []
ApplicationModel_Activation = ["ApplicationModel"]
ApplicationModel_AppExtensions = ["ApplicationModel"]
ApplicationModel_AppService = ["ApplicationModel", "Foundation"]
ApplicationModel_Appointments = ["ApplicationModel"]
ApplicationModel_Appointments_AppointmentsProvider = ["ApplicationModel_Appointments"]
ApplicationModel_Appointments_DataProvider = ["ApplicationModel_Appointments"]
fn main() {
use reader::*;
let reader = TypeReader::get_mut();
fn walk(tree: &TypeTree) {
for (_, entry) in &tree.types {
match &entry.def {
ElementType::TypeDef(def) => {
if def.has_attribute("SupportedArchitectureAttribute") {
assert!(def.kind() == TypeKind::Struct || def.kind() == TypeKind::Delegate);
@kennykerr
kennykerr / cppwinrt.cpp
Last active September 28, 2021 23:11
Language Overhead
// C++/winRT via https://github.com/microsoft/cppwinrt
#include "winrt/Windows.System.Power.h"
int main()
{
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 10'000'000; i++)
{
use Windows::Win32::System::Com::*;
use Windows::Win32::UI::Accessibility::*;
use Windows::Win32::UI::WindowsAndMessaging::*;
use Windows::UI::UIAutomation::*;
fn main() -> Result<()> {
unsafe {
CoInitializeEx(std::ptr::null_mut(), COINIT_MULTITHREADED)?;
let window = FindWindowA(None, "Calculator");
@kennykerr
kennykerr / sample.rs
Created July 14, 2021 19:06
Query the service control manager using the Windows crate
fn main() -> Result<()> {
unsafe {
let scm = OpenSCManagerA(None, None, GENERIC_READ);
let service = OpenServiceA(scm, "Fax", GENERIC_READ);
let mut buffer_size = 0;
QueryServiceStatusEx(
service,
SC_STATUS_PROCESS_INFO,
@kennykerr
kennykerr / file_bytes.rs
Created May 28, 2021 20:32
Static memory mapped file in Rust
pub fn file_bytes(filename: &std::path::PathBuf) -> &'static [u8] {
let mut filename = String::from(filename.as_path().to_str().expect("Unexpected file name"));
filename.push('\0');
let file = unsafe {
CreateFileA(
filename.as_bytes().as_ptr(),
FILE_GENERIC_READ,
FILE_SHARE_READ,
#[implement(
extend Windows::UI::Xaml::Application,
override OnLaunched,
Windows::Foundation::IStringable,
)]
struct App {
}
impl App {
fn OnLaunched(&self, _: &LaunchActivatedEventArgs) -> Result<()> {
{
"Windows.AI.MachineLearning": {
"Windows.Foundation",
"Windows.Foundation.Collections",
},
"Windows.AI.MachineLearning.Preview": {
"Windows.Foundation.Collections",
},
"Windows.ApplicationModel.AppService": {
"Windows.Foundation",