WinUtil/Readme.md

35 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# WinUtil
Tools for Windows Program Developing.
## `class SharedMemory` 共享内存类
构造时可选择打开或新建共享内存,通过名称指定共享内存,传入参数以创建共享内存. 析构时会自动关闭或释放共享内存
主要API:
`bool isReady() const` 用于检查共享内存是否就绪
`void* get()` 返回共享内存. 该内存有效长度为创造时指定的长度.
## `class NamedMutex` 命名互斥量
构造时可选择获取或新建命名互斥量通过create参数指定默认为打开. 析构时仅清理句柄资源,不会改变互斥量的状态.
主要API:
`bool isReady() const` 用于检查命名互斥量是否正确打开(句柄检查)
`DWORD getError() const` 获取上一次WINAPI操作的错误码
`int wait()` 等待互斥量就绪(如果互斥量当前不被本线程占有,则等待直到本线程获取到互斥量)
`int wait_for(int ms)` 等待互斥量就绪,最多等待ms毫秒.
返回值:
1 成功获取到互斥锁
0 超时
-1 出现错误(此情况会重置错误码)
`void release()` 释放互斥量