Some specific API (e.g. Windows AI API) requires package identity at runtime.
You need to make your application packaged.
| # https://learn.microsoft.com/en-us/windows/ai/apis/phi-silica | |
| import asyncio | |
| from win32more.Microsoft.Windows.AI import AIFeatureReadyState | |
| from win32more.Microsoft.Windows.AI.Text import LanguageModel | |
| from win32more.Windows.ApplicationModel import LimitedAccessFeatures, LimitedAccessFeatureStatus | |
| # You need to obtain LAF access token. See url above. | |
| LAF_FEATURE_ID = "" |
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], |
| # shadowing definition by decorator | |
| import sys | |
| class shadowing: | |
| def __new__(cls, klass): | |
| self = super().__new__(cls) | |
| self._klass = klass | |
| setattr(sys.modules[klass.__module__], klass.__name__, self) | |
| return klass |