Skip to content

Instantly share code, notes, and snippets.

View kennykerr's full-sized avatar

Kenny Kerr kennykerr

View GitHub Profile
{
"Windows.AI.MachineLearning": {
"Windows.Foundation",
"Windows.Foundation.Collections",
},
"Windows.AI.MachineLearning.Preview": {
"Windows.Foundation.Collections",
},
"Windows.ApplicationModel.AppService": {
"Windows.Foundation",
use bindings::windows::storage::UserDataPaths;
fn main() -> windows::Result<()> {
let path = UserDataPaths::get_default()?.local_app_data()?;
println!("{}", path);
Ok(())
}
use bindings::{
windows::win32::com::CoTaskMemFree,
windows::win32::shell::SHGetKnownFolderPath,
windows::win32::system_services::{HANDLE, PWSTR},
};
fn known_folder_path(id: &windows::Guid) -> windows::Result<String> {
unsafe {
let mut path = PWSTR::default();
SHGetKnownFolderPath(id, 0, HANDLE(0), &mut path).ok()?;
use bindings::{windows::win32::intl::*, windows::*};
fn main() -> Result<()> {
initialize_mta()?;
let factory: ISpellCheckerFactory = create_instance(&SpellCheckerFactory)?;
let locale = HString::from("en-US");
let mut supported = FALSE;
unsafe {
winrt::declare!(
// A WinRT struct defined here
pub struct StructType { x: i32, y: i32 };
// A WinRT interface defined here (uuid is inferred)
// Implemented by the class itself.
pub interface IClassType {
fn method(&self) -> Result<i32>;
}
com::declare!(
// A COM interface
[uuid(...)]
pub interface IComInterface {
fn foo(&self);
fn bar(&self);
}
// A public COM class must have a [uuid]
com::declare!(
// A COM interface declared here
[uuid(...)]
interface IOldSchool {...}
// A COM class declared here (not defined here)
[uuid(...)]
class ExternalClass : IOldSchool;
#include <Unknwn.h>
#include <winrt/Windows.Foundation.h>
using namespace winrt;
using namespace Windows::Foundation;
static constexpr GUID server_clsid // DAA16D7F-EF66-4FC9-B6F2-3E5B6D924576
{
0xdaa16d7f, 0xef66, 0x4fc9, { 0xb6, 0xf2, 0x3e, 0x5b, 0x6d, 0x92, 0x45, 0x76 }
};
#include <Unknwn.h>
#include <winrt/Windows.Foundation.h>
using namespace winrt;
using namespace Windows::Foundation;
struct Stringable : implements<Stringable, IStringable>
{
hstring ToString()
{
#include "winrt/Windows.Foundation.h"
using namespace winrt;
using namespace Windows::Foundation;
using namespace std::chrono;
IAsyncAction wait_for(TimeSpan duration)
{
co_await duration;
printf("done %lld\n", duration.count());