Some specific API (e.g. Windows AI API) requires package identity at runtime.
You need to make your application packaged.
| # 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 |
| # 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). |
Some specific API (e.g. Windows AI API) requires package identity at runtime.
You need to make your application packaged.
| // 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 | |
| // ... |
| # 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 |
| # 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), |
| # 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 |
| # 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, |
| # 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 |
| // 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], |