WinUtil/WinUtil.h

39 lines
731 B
C
Raw Permalink Normal View History

2017-11-16 21:47:54 +08:00
#include <string>
#include <windows.h>
class SharedMemory
{
public:
/// Open a shared memory
SharedMemory(const std::string& name);
/// Create a shared memory
SharedMemory(const std::string& name,int size);
/// auto close, destroy memory.
~SharedMemory();
bool isReady() const;
void* get();
private:
HANDLE hMap;
void* pMem;
};
class NamedMutex
{
public:
NamedMutex(const std::string& name,bool create=false);
~NamedMutex();
bool isReady() const;
DWORD getError() const;
/// If the mutex has been occupied by this process, wait() will return immediately.
2017-11-16 22:05:19 +08:00
int wait();
int wait_for(int ms);
2017-11-16 21:47:54 +08:00
void release();
private:
HANDLE hmtx;
DWORD errcode;
};