Skip to content

Instantly share code, notes, and snippets.

View kennykerr's full-sized avatar

Kenny Kerr kennykerr

View GitHub Profile
use std::sync::RwLock;
fn main() {
let connection = Connection::new();
// Depends on `Send` to move the connection "onto" the thread.
let thread = std::thread::spawn(move || {
connection.write();
println!("{}", connection.read());
// The connection is dropped here.
use windows::{
core::{HSTRING, PWSTR},
Win32::Foundation::UNICODE_STRING,
};
fn main() {
let us = UnicodeString::new("hello world");
dbg!(&us);
unsafe {
using namespace winrt;
using namespace Windows::Foundation;
struct Base: implements<Base, composable, IStringable>
{
static IInspectable CreateInstance(IInspectable const& base, IInspectable& inner)
{
return impl::composable_factory<Base>::CreateInstance<IInspectable>(base, inner);
}
D:\git\scratch10>type src\main.rs
use windows_sys::{core::*, Win32::System::LibraryLoader::*};
fn main() {
unsafe {
let module = LoadLibraryExW(
w!("api-ms-win-core-com-l1-1-3.dll"),
core::ptr::null_mut(),
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS,
);
use windows_core::*;
#[interface("1bd72b4b-8d05-44c6-8909-da3e0e91afa0")]
unsafe trait IDebug: IUnknown {
fn debug_carrot(&self, carrot: Ref<ICarrot>) -> Result<()>;
fn debug_pear(&self, pear: Ref<IPear>) -> Result<()>;
}
#[interface("3bde3f9e-4d7c-4d5f-8322-4b226e0e1b91")]
unsafe trait ICarrot: IUnknown {
use windows::{core::*, Win32::Storage::FileSystem::*};
fn search_path(filename: &str) -> Result<String> {
let filename = &HSTRING::from(filename);
let len = unsafe { SearchPathW(None, filename, None, None, None) };
if len == 0 {
return Err(Error::from_win32());
}
use windows::core::*;
use windows::Win32::System::Com::*;
use windows::Win32::UI::Accessibility::*;
use windows::Win32::UI::WindowsAndMessaging::*;
fn main() -> Result<()> {
unsafe {
let mut acc: Option<IAccessible> = None;
AccessibleObjectFromWindow(
GetDesktopWindow(),
[dependencies.windows]
version = "0.52"
features = [
"Win32_Foundation",
"Win32_System_LibraryLoader",
]
@kennykerr
kennykerr / Cargo.toml
Last active November 14, 2023 15:51
RtlGetVersion
[dependencies.windows]
version = "0.51"
features = ["Win32_Foundation", "Win32_System_SystemInformation", "Wdk_System_SystemServices"]
#include "pch.h"
using namespace winrt;
using namespace Windows::Foundation;
IAsyncAction Sample()
{
throw winrt::hresult_invalid_argument(L"yolo");
}