ms-win32
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWin32 Discipline
Win32 规范准则
Invoke for ANY code touching Windows APIs: / functions from kernel32/user32/advapi32/ole32/shell32 and friends, COM interfaces, handles (, , ), registry, services, or shell — in any language, however trivial the snippet.
*W*AHANDLEHWNDHDC任何涉及Windows API的代码都需遵循此准则:包括kernel32/user32/advapi32/ole32/shell32等库中的/函数、COM接口、句柄(、、)、注册表、服务或Shell相关代码——无论使用何种语言,即使是简单的代码片段也不例外。
*W*AHANDLEHWNDHDCNon-negotiables
不可协商的规则
- Unicode APIs only, never
W. Text is UTF-16 or UTF-8 only; neverAor any ANSI/narrow encoding for durable or protocol text.CP_ACP - Bytes are not UTF-16 code units. Honor exact length contracts and terminators; never assume null termination when a length is supplied.
- Check documented failure values. /
FAILEDforSUCCEEDED;HRESULTforERROR_SUCCESS; captureLSTATUSonly where documented — many calls invalidate it.GetLastError() - RAII ownership with matching release for handles, buffers, and COM allocations; never release borrowed or pseudo-handles. Initialize structure size/version fields (etc.) as documented; use pointer-sized types (
cbSize,DWORD_PTR) without truncation.INT_PTR
When a rule here conflicts with an API's documented contract, the documented contract wins — note the deviation.
- 仅使用Unicode API,绝对禁止使用
W版本。 文本仅采用UTF-16或UTF-8编码;对于持久化或协议文本,绝不能使用A或任何ANSI/窄编码。CP_ACP - 字节不等同于UTF-16代码单元。 严格遵守精确的长度约定和终止符;当提供长度时,绝不要假设存在空终止符。
- 检查文档化的失败值。 对使用
HRESULT/FAILED宏;对SUCCEEDED检查LSTATUS;仅在文档明确说明的情况下捕获ERROR_SUCCESS——许多调用会使该值失效。GetLastError() - 对句柄、缓冲区和COM分配采用RAII所有权机制并匹配释放操作;绝不要释放借用的句柄或伪句柄。 按照文档要求初始化结构体的大小/版本字段(如等);使用指针大小的类型(
cbSize、DWORD_PTR),避免截断。INT_PTR
如果此处的规则与API的文档化约定冲突,以文档化约定为准——请注明偏差情况。