Skip to content

Instantly share code, notes, and snippets.

@ynkdir
ynkdir / calc_laf_token.py
Last active November 14, 2025 15:56
Caliculate Windows Limited Access Feature Token
# Caliculate Windows Limited Access Feature Token
# https://firefox-source-docs.mozilla.org/widget/windows/LimitedAccessFeature.html
# term:
# Limited Access Feature (laf)
# Package Family Name (pfn)
import winreg
from base64 import b64encode
from hashlib import sha256
@ynkdir
ynkdir / phi-silica.py
Last active November 8, 2025 14:08
Test Phi Silica
# https://learn.microsoft.com/en-us/windows/ai/apis/phi-silica
# https://learn.microsoft.com/en-us/windows/ai/
# https://github.com/ynkdir/py-win32more/blob/main/docs/howto-create-packaged-application.md
#
# To use AI Api,
# 1. Unlock Limited Access Feature (fill the following variable). See url above to request access token.
# 2. Make application (python.exe) packaged with package family name used to request access token.
# (It seems to available for unpackaged application, but I can not get it work.)
#
# There is a problem in Phi Silica API access through LAF (resolved by KB5067036).
@ynkdir
ynkdir / howto-create-packaged-application.md
Last active October 23, 2025 13:07
How to create packaged application.
@ynkdir
ynkdir / msvcp140_dll_incompatible.cpp
Last active September 28, 2025 04:59
There are multiple versions of msvcp140.dll. And they are not forward compatible.
// There are multiple versions of msvcp140.dll.
// If C++ program is compiled with newer version, it will not work with older
// version of msvcp140.dll.
//
// You can check file version with PS> (Get-Item msvcp140.dll).VersionInfo
//
// https://learn.microsoft.com/en-us/cpp/porting/binary-compat-2015-2017?view=msvc-170
// ```
// C++ binary compatibility between Visual Studio versions
// ...
@ynkdir
ynkdir / windows_ml_example.py
Last active September 27, 2025 12:38
Windows ML example
# Load and predict with ONNX Runtime and a very simple model
# https://onnxruntime.ai/docs/api/python/auto_examples/plot_load_and_predict.html
#
# Install
# https://learn.microsoft.com/en-us/windows/ai/new-windows-ml/get-started?tabs=python>
# pip install win32more
# pip install --pre --index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ --extra-index-url https://pypi.org/simple onnxruntime-winml
import asyncio
@ynkdir
ynkdir / memoryview_pointer.py
Created September 20, 2025 14:10
How to get pointer of memoryview (and how to break python object)
# How to get pointer of memoryview (and how to break python object)
from ctypes import *
PyBUF_FULL_RO = 0x0100 | 0x0010 | 0x0008 | 0x0004
class Py_buffer(Structure):
_fields_ = [
("buf", c_void_p),
("obj", c_void_p),
@ynkdir
ynkdir / winui3_webview2_environment_example.py
Last active September 20, 2025 05:11
Example to use WebView2 with CoreWebView2Environment.CreateWithOptionsAsync()
# Example to use WebView2 with CoreWebView2Environment.CreateWithOptionsAsync().
import asyncio
from win32more.Microsoft.UI.Xaml import Window
from win32more.Microsoft.UI.Xaml.Controls import WebView2
from win32more.Microsoft.Web.WebView2.Core import CoreWebView2Environment, CoreWebView2EnvironmentOptions
from win32more.Windows.Foundation import Uri
from win32more.appsdk.xaml import XamlApplication
@ynkdir
ynkdir / winui3_show_pil_image.py
Last active September 21, 2025 17:13
WinUI3 example for SoftwareBitmap
# How to show a PIL image in WinUI
import io
from PIL import Image
from win32more.Microsoft.UI.Xaml.Media.Imaging import BitmapImage, SoftwareBitmapSource
from win32more.Microsoft.Windows.Storage.Pickers import FileOpenPicker
from win32more.Windows.Graphics.Imaging import (
BitmapAlphaMode,
BitmapBufferAccessMode,
@ynkdir
ynkdir / winui3_thread_example.py
Created August 20, 2025 17:03
WinUI3 example for accessing UI component in worker thread.
# WinUI3 example for accessing UI component in subthread.
# UI component cannot be accessed in subthread.
# Use asyncio or DispatcherQueue to execute command in mainthread.
import asyncio
import threading
import time
from win32more.Microsoft.UI.Dispatching import DispatcherQueue
from win32more.Microsoft.UI.Xaml.Media import SolidColorBrush
@ynkdir
ynkdir / main.rs
Last active August 2, 2025 15:45
rust logging allocator
// https://doc.rust-lang.org/std/alloc/struct.System.html
use std::alloc::{GlobalAlloc, Layout, System};
use std::io::Write;
static HEX: [[u8; 1]; 16] = [
[0x30],
[0x31],
[0x32],
[0x33],