30 lines
1.1 KiB
Markdown
30 lines
1.1 KiB
Markdown
---
|
||
tags:
|
||
aliases:
|
||
date: 2025-03-12
|
||
time: 19:58:20
|
||
description:
|
||
---
|
||
|
||
# docstring
|
||
Add docstring in English to each classes and functions.
|
||
|
||
# swig 教學文
|
||
閱讀 https://www.swig.org/ 這個網站,寫一篇教學文,教導如何使用 swig 這個工具來將 C++ library 包裝成 Python library。
|
||
教學要從簡單到進階,每一階段都要給出範例與解說。
|
||
|
||
範例建立一個 C++ 的 class,分3階段將這個class複雜化,並用 swig 建立 Python library。
|
||
作業系統: Windows 11
|
||
編譯環境: Visual Studio 2022
|
||
Python 版本: 3.12
|
||
|
||
# Create global mutex
|
||
Use `ctypes` and Win32Api `CreateMutex` to create a global mutex here. Use class to wrap it.
|
||
This mutex shoid has these features:
|
||
1. When user instantiate this class, use Win32api `OpenMutex` to try to open this global mutex, because this mutex mybe alreday created in another process.
|
||
2. if `OpenMutex` failed, use `CreateMutex` to create the global mutex.
|
||
3. this class should provide lock and unlock function, use `WaitForSingleObject` and `ReleaseMutex` to implement it.
|
||
4. And, very important, class should has `release` function of mutex.
|
||
|
||
|
||
# 參考來源 |