2019-08-19 19:19:58 +08:00
|
|
|
|
#ifndef HGL_OS_WIN_INCLUDE
|
|
|
|
|
#define HGL_OS_WIN_INCLUDE
|
|
|
|
|
|
|
|
|
|
#include<malloc.h>
|
|
|
|
|
#include<winsock2.h> //winsock2必须在Windows.h前面,不然会报错
|
|
|
|
|
#include<windows.h>
|
2020-07-07 19:14:42 +08:00
|
|
|
|
#include<uchar.h>
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
|
|
|
|
#undef min
|
|
|
|
|
#undef max
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
using u32char =char32_t;
|
|
|
|
|
using u16char =wchar_t;
|
|
|
|
|
using os_char =wchar_t;
|
2020-07-07 19:14:42 +08:00
|
|
|
|
|
2019-08-19 19:19:58 +08:00
|
|
|
|
#define to_oschar to_u16
|
|
|
|
|
#define OS_TEXT(str) L##str
|
|
|
|
|
#define U8_TEXT(str) u8##str
|
|
|
|
|
#define U16_TEXT(str) L##str
|
2020-07-08 10:48:16 +08:00
|
|
|
|
#define U32_TEXT(str) U##str
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
2020-04-13 15:32:22 +08:00
|
|
|
|
#define os_main wmain
|
|
|
|
|
#define os_out std::wcout
|
|
|
|
|
#define os_in std::wcin
|
|
|
|
|
#define os_err std::wcerr
|
|
|
|
|
#define os_log std::wclog
|
|
|
|
|
|
2019-08-19 19:19:58 +08:00
|
|
|
|
#define HGL_OS_NAME OS_TEXT("Windows")
|
|
|
|
|
|
|
|
|
|
#if HGL_CPU == HGL_CPU_X86_32
|
|
|
|
|
#define HGL_LIB_OS "Win32" //库操作系统前缀
|
|
|
|
|
#elif HGL_CPU == HGL_CPU_X86_64
|
|
|
|
|
#define HGL_LIB_OS "Win64" //库操作系统前缀
|
|
|
|
|
#endif//HGL_CPU
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
#define HGL_PLUGIN_FRONTNAME OS_TEXT("CMP.") //插件文件名前缀
|
|
|
|
|
#define HGL_PLUGIN_EXTNAME OS_TEXT(".DLL") //插件文件扩展名
|
|
|
|
|
#define HGL_PLUGIN_FUNC extern "C" __declspec(dllexport) //插件函数定义
|
|
|
|
|
|
2020-11-09 13:14:06 +08:00
|
|
|
|
#define HGL_DIRECTORY_SEPARATOR_RAWCHAR '\\' //目录分隔符
|
2021-09-04 13:42:51 +08:00
|
|
|
|
#define HGL_DIRECTORY_SEPARATOR_RAWSTR "\\" //目录分隔符
|
2019-08-19 19:19:58 +08:00
|
|
|
|
#define HGL_DIRECTORY_SEPARATOR OS_TEXT('\\') //目录分隔符
|
|
|
|
|
#define HGL_DIRECTORY_SEPARATOR_STR OS_TEXT("\\") //目录分隔符
|
|
|
|
|
#define HGL_DIRECTORY_SEPARATOR_U8STR U8_TEXT("\\")
|
|
|
|
|
|
|
|
|
|
#define HGL_LINE_END OS_TEXT("\r\n") //换行符
|
|
|
|
|
#define HGL_LINE_END_SIZE 2 //换行符长度
|
|
|
|
|
|
2021-09-07 13:07:47 +08:00
|
|
|
|
/**
|
|
|
|
|
* 从Windows 10(ver 1607)开始,NTFS分区文件名最大长度为32767。
|
|
|
|
|
* 但由于文件系统的不同,我们需要使用 GetVolumeInformation 函数,根据参数lpMaximumComponentLength的返回值来确定每个分区可使用的最大长度
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define HGL_MAX_PATH MAX_PATH //文件名最大长度
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
|
|
|
|
#define HGL_MEM_ALIGN 16 //内存对齐字节数
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-07-10 17:01:59 +08:00
|
|
|
|
|
|
|
|
|
// == 目前MINGW和MSVC在以下接口上应该能保持一致了
|
|
|
|
|
|
|
|
|
|
#define hgl_malloc(size) _aligned_malloc(size,HGL_MEM_ALIGN)
|
|
|
|
|
#define hgl_realloc(ptr,size) _aligned_realloc(ptr,size,HGL_MEM_ALIGN)
|
|
|
|
|
#define hgl_free _aligned_free
|
|
|
|
|
|
2021-03-07 20:01:13 +08:00
|
|
|
|
inline void *hgl_align_malloc(size_t n,size_t align_size)
|
2021-02-23 19:55:53 +08:00
|
|
|
|
{
|
|
|
|
|
if(n<=0)return(nullptr);
|
|
|
|
|
|
2021-03-07 20:01:13 +08:00
|
|
|
|
if(align_size==0)
|
|
|
|
|
align_size=HGL_MEM_ALIGN;
|
|
|
|
|
|
2021-02-23 19:55:53 +08:00
|
|
|
|
return _aligned_malloc(n,align_size);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 17:01:59 +08:00
|
|
|
|
template<typename T>
|
2020-09-19 14:57:53 +08:00
|
|
|
|
inline T *hgl_align_malloc(size_t n)
|
2020-07-10 17:01:59 +08:00
|
|
|
|
{
|
2020-10-22 18:55:21 +08:00
|
|
|
|
if(n<=0)return(nullptr);
|
|
|
|
|
|
2020-07-10 17:01:59 +08:00
|
|
|
|
return (T *)_aligned_malloc(n*sizeof(T),alignof(T));
|
|
|
|
|
}
|
2019-08-19 19:19:58 +08:00
|
|
|
|
|
2021-03-07 20:01:13 +08:00
|
|
|
|
inline void *hgl_align_realloc(void *ptr,size_t n,size_t align_size)
|
2021-02-23 19:55:53 +08:00
|
|
|
|
{
|
|
|
|
|
if(n<=0)
|
|
|
|
|
{
|
|
|
|
|
if(ptr)
|
|
|
|
|
_aligned_free(ptr);
|
|
|
|
|
|
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-07 20:01:13 +08:00
|
|
|
|
if(align_size==0)
|
|
|
|
|
align_size=HGL_MEM_ALIGN;
|
|
|
|
|
|
2021-02-23 19:55:53 +08:00
|
|
|
|
if(ptr)
|
|
|
|
|
return _aligned_realloc(ptr,n,align_size);
|
|
|
|
|
else
|
|
|
|
|
return _aligned_malloc(n,align_size);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-19 14:57:53 +08:00
|
|
|
|
template<typename T>
|
|
|
|
|
inline T *hgl_align_realloc(T *ptr,size_t n)
|
|
|
|
|
{
|
2020-10-22 18:55:21 +08:00
|
|
|
|
if(n<=0)
|
|
|
|
|
{
|
2021-02-23 19:55:53 +08:00
|
|
|
|
if(ptr)
|
|
|
|
|
_aligned_free(ptr);
|
|
|
|
|
|
2020-10-22 18:55:21 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ptr)
|
|
|
|
|
return (T *)_aligned_realloc(ptr,n*sizeof(T),alignof(T));
|
|
|
|
|
else
|
2021-02-23 19:55:53 +08:00
|
|
|
|
return (T *)_aligned_malloc(n*sizeof(T),alignof(T));
|
2020-09-19 14:57:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 19:19:58 +08:00
|
|
|
|
#define OS_EXTERNAL_H <winbase.h>
|
2019-12-10 14:38:29 +08:00
|
|
|
|
using ExternalModulePointer =HMODULE;
|
2019-08-19 19:19:58 +08:00
|
|
|
|
#define pi_get GetProcAddress
|
|
|
|
|
#define pi_close FreeLibrary
|
|
|
|
|
|
2020-07-10 17:01:59 +08:00
|
|
|
|
#ifdef HGL_64_BITS
|
|
|
|
|
#define struct_stat64 struct _stat64
|
|
|
|
|
#define hgl_lstat64 _wstat64
|
|
|
|
|
#endif
|
|
|
|
|
#if HGL_32_BITS
|
|
|
|
|
#define struct_stat64 struct _stati64
|
|
|
|
|
#define hgl_lstat64 _wstat32i64
|
|
|
|
|
#endif
|
2019-08-19 19:19:58 +08:00
|
|
|
|
//#define hgl_stat64 _stat64
|
|
|
|
|
#define hgl_lseek64 _lseeki64
|
|
|
|
|
#define hgl_tell64(fp) _telli64(fp)
|
|
|
|
|
#define hgl_fstat64 _fstati64
|
|
|
|
|
#define hgl_read64 _read
|
|
|
|
|
#define hgl_write64 _write
|
|
|
|
|
|
2019-12-10 15:05:56 +08:00
|
|
|
|
using thread_mutex_ptr =CRITICAL_SECTION;
|
2019-08-19 19:19:58 +08:00
|
|
|
|
using thread_ptr =HANDLE;
|
2019-12-10 14:38:29 +08:00
|
|
|
|
using rwlock_ptr =SRWLOCK;
|
|
|
|
|
using semaphore_ptr =HANDLE;
|
2020-02-08 15:03:07 +08:00
|
|
|
|
using cond_var_ptr =CONDITION_VARIABLE;
|
2019-12-10 14:38:29 +08:00
|
|
|
|
|
2019-08-19 19:19:58 +08:00
|
|
|
|
#define THREAD_FUNC DWORD WINAPI
|
|
|
|
|
#define HGL_THREAD_DETACH_SELF
|
2019-12-10 15:05:56 +08:00
|
|
|
|
|
|
|
|
|
using proc_mutex_ptr =HANDLE;
|
2019-08-19 19:19:58 +08:00
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
#endif//HGL_OS_WIN_INCLUDE
|