win32_api.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 427 行 · 第 1/2 页
HPP
427 行
extern "C" __declspec(dllimport) unsigned long __stdcall GetLastError();extern "C" __declspec(dllimport) void * __stdcall GetCurrentProcess();extern "C" __declspec(dllimport) int __stdcall CloseHandle(void*);extern "C" __declspec(dllimport) int __stdcall DuplicateHandle ( void *hSourceProcessHandle, void *hSourceHandle , void *hTargetProcessHandle, void **lpTargetHandle , unsigned long dwDesiredAccess, int bInheritHandle , unsigned long dwOptions);extern "C" __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(interprocess_filetime*);extern "C" __declspec(dllimport) int __stdcall FileTimeToLocalFileTime(const interprocess_filetime *in, const interprocess_filetime *out);extern "C" __declspec(dllimport) void * __stdcall CreateMutexA(interprocess_security_attributes*, int, const char *);extern "C" __declspec(dllimport) void * __stdcall OpenMutexA(unsigned long, int, const char *);extern "C" __declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void *, unsigned long);extern "C" __declspec(dllimport) int __stdcall ReleaseMutex(void *);extern "C" __declspec(dllimport) int __stdcall UnmapViewOfFile(void *);extern "C" __declspec(dllimport) void * __stdcall CreateSemaphoreA(interprocess_security_attributes*, long, long, const char *);extern "C" __declspec(dllimport) int __stdcall ReleaseSemaphore(void *, long, long *);extern "C" __declspec(dllimport) void * __stdcall OpenSemaphoreA(unsigned long, int, const char *);extern "C" __declspec(dllimport) void * __stdcall CreateFileMappingA (void *, interprocess_security_attributes*, unsigned long, unsigned long, unsigned long, const char *);extern "C" __declspec(dllimport) void * __stdcall MapViewOfFileEx (void *, unsigned long, unsigned long, unsigned long, std::size_t, void*);extern "C" __declspec(dllimport) void * __stdcall OpenFileMappingA (unsigned long, int, const char *);extern "C" __declspec(dllimport) void * __stdcall CreateFileA (const char *, unsigned long, unsigned long, struct interprocess_security_attributes*, unsigned long, unsigned long, void *);extern "C" __declspec(dllimport) int __stdcall DeleteFileA (const char *);extern "C" __declspec(dllimport) int __stdcall MoveFileExA (const char *, const char *, unsigned long);extern "C" __declspec(dllimport) void __stdcall GetSystemInfo (struct system_info *);extern "C" __declspec(dllimport) int __stdcall FlushViewOfFile (void *, std::size_t);extern "C" __declspec(dllimport) int __stdcall GetFileSizeEx (void *, __int64 *size);extern "C" __declspec(dllimport) unsigned long __stdcall FormatMessageA (unsigned long dwFlags, const void *lpSource, unsigned long dwMessageId, unsigned long dwLanguageId, char *lpBuffer, unsigned long nSize, std::va_list *Arguments);extern "C" __declspec(dllimport) void *__stdcall LocalFree (void *);extern "C" __declspec(dllimport) int __stdcall CreateDirectoryA(const char *, interprocess_security_attributes*);extern "C" __declspec(dllimport) int __stdcall GetTempPathA(unsigned long length, char *buffer);extern "C" __declspec(dllimport) int __stdcall CreateDirectory(const char *, interprocess_security_attributes*);extern "C" __declspec(dllimport) int __stdcall SetFileValidData(void *, __int64 size);extern "C" __declspec(dllimport) int __stdcall SetEndOfFile(void *);extern "C" __declspec(dllimport) int __stdcall SetFilePointerEx(void *, __int64 distance, __int64 *new_file_pointer, unsigned long move_method);extern "C" __declspec(dllimport) int __stdcall LockFile (void *hnd, unsigned long offset_low, unsigned long offset_high, unsigned long size_low, unsigned long size_high);extern "C" __declspec(dllimport) int __stdcall UnlockFile(void *hnd, unsigned long offset_low, unsigned long offset_high, unsigned long size_low, unsigned long size_high);extern "C" __declspec(dllimport) int __stdcall LockFileEx(void *hnd, unsigned long flags, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped* overlapped);extern "C" __declspec(dllimport) int __stdcall UnlockFileEx(void *hnd, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped* overlapped);extern "C" __declspec(dllimport) int __stdcall WriteFile(void *hnd, const void *buffer, unsigned long bytes_to_write, unsigned long *bytes_written, interprocess_overlapped* overlapped);extern "C" __declspec(dllimport) int __stdcall InitializeSecurityDescriptor(interprocess_security_descriptor *pSecurityDescriptor, unsigned long dwRevision);extern "C" __declspec(dllimport) int __stdcall SetSecurityDescriptorDacl(interprocess_security_descriptor *pSecurityDescriptor, int bDaclPresent, interprocess_acl *pDacl, int bDaclDefaulted);} //namespace winapi {} //namespace interprocess {} //namespace boost {#else# include <windows.h>#endif //#if !defined( BOOST_USE_WINDOWS_H )namespace boost {namespace interprocess {namespace winapi {static inline unsigned long format_message (unsigned long dwFlags, const void *lpSource, unsigned long dwMessageId, unsigned long dwLanguageId, char *lpBuffer, unsigned long nSize, std::va_list *Arguments){ return FormatMessageA (dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);}//And now, wrapper functionsstatic inline void * local_free(void *hmem){ return LocalFree(hmem); }static inline unsigned long make_lang_id(unsigned long p, unsigned long s){ return ((((unsigned short)(s)) << 10) | (unsigned short)(p)); }static inline void sched_yield(){ Sleep(1); }static inline unsigned long get_current_thread_id(){ return GetCurrentThreadId(); }static inline unsigned long get_current_process_id(){ return GetCurrentProcessId(); }static inline unsigned int close_handle(void* handle){ return CloseHandle(handle); }static inline bool duplicate_current_process_handle (void *hSourceHandle, void **lpTargetHandle){ return 0 != DuplicateHandle ( GetCurrentProcess(), hSourceHandle, GetCurrentProcess() , lpTargetHandle, 0, 0 , duplicate_same_access);}static inline unsigned long get_last_error(){ return GetLastError(); }static inline void get_system_time_as_file_time(interprocess_filetime *filetime){ GetSystemTimeAsFileTime(filetime); }static inline bool file_time_to_local_file_time (const interprocess_filetime *in, const interprocess_filetime *out){ return 0 != FileTimeToLocalFileTime(in, out); }static inline void *create_mutex(const char *name){ return CreateMutexA(0, 0, name); }static inline void *open_mutex(const char *name){ return OpenMutexA(mutex_all_access, 0, name); }static inline unsigned long wait_for_single_object(void *handle, unsigned long time){ return WaitForSingleObject(handle, time); }static inline int release_mutex(void *handle){ return ReleaseMutex(handle); }static inline int unmap_view_of_file(void *address){ return UnmapViewOfFile(address); }static inline void *create_semaphore(long initialCount, const char *name){ return CreateSemaphoreA(0, initialCount, (long)(((unsigned long)(-1))>>1), name); }static inline int release_semaphore(void *handle, long release_count, long *prev_count){ return ReleaseSemaphore(handle, release_count, prev_count); }static inline void *open_semaphore(const char *name){ return OpenSemaphoreA(semaphore_all_access, 1, name); }static inline void * create_file_mapping (void * handle, unsigned long access, unsigned long high_size, unsigned long low_size, const char * name){ interprocess_security_attributes sa; interprocess_security_descriptor sd; if(!InitializeSecurityDescriptor(&sd, security_descriptor_revision)) return 0; if(!SetSecurityDescriptorDacl(&sd, true, 0, false)) return 0; sa.lpSecurityDescriptor = &sd; sa.nLength = sizeof(interprocess_security_attributes); sa.bInheritHandle = false; return CreateFileMappingA (handle, &sa, access, high_size, low_size, name); //return CreateFileMappingA (handle, 0, access, high_size, low_size, name); }static inline void * open_file_mapping (unsigned long access, const char *name){ return OpenFileMappingA (access, 0, name); }static inline void *map_view_of_file_ex(void *handle, unsigned long file_access, unsigned long highoffset, unsigned long lowoffset, std::size_t numbytes, void *base_addr){ return MapViewOfFileEx(handle, file_access, highoffset, lowoffset, numbytes, base_addr); }static inline void *create_file(const char *name, unsigned long access, unsigned long creation_flags, unsigned long attributes = 0){ return CreateFileA(name, access, file_share_read | file_share_write | file_share_delete, 0, creation_flags, attributes, 0); }static inline bool delete_file(const char *name){ return 0 != DeleteFileA(name); }static inline bool move_file_ex(const char *source_filename, const char *destination_filename, unsigned long flags){ return 0 != MoveFileExA(source_filename, destination_filename, flags); }static inline void get_system_info(system_info *info){ GetSystemInfo(info); }static inline int flush_view_of_file(void *base_addr, std::size_t numbytes){ return FlushViewOfFile(base_addr, numbytes); }static inline bool get_file_size(void *handle, __int64 &size){ return 0 != GetFileSizeEx(handle, &size); }static inline bool create_directory(const char *name, interprocess_security_attributes* security){ return 0 != CreateDirectoryA(name, security); }static inline unsigned long get_temp_path(unsigned long length, char *buffer){ return GetTempPathA(length, buffer); }static inline int set_end_of_file(void *handle){ return 0 != SetEndOfFile(handle); }static inline bool set_file_pointer_ex(void *handle, __int64 distance, __int64 *new_file_pointer, unsigned long move_method){ return 0 != SetFilePointerEx(handle, distance, new_file_pointer, move_method); }static inline bool lock_file_ex(void *hnd, unsigned long flags, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped){ return 0 != LockFileEx(hnd, flags, reserved, size_low, size_high, overlapped); }static inline bool unlock_file_ex(void *hnd, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped){ return 0 != UnlockFileEx(hnd, reserved, size_low, size_high, overlapped); }static inline bool write_file(void *hnd, const void *buffer, unsigned long bytes_to_write, unsigned long *bytes_written, interprocess_overlapped* overlapped){ return 0 != WriteFile(hnd, buffer, bytes_to_write, bytes_written, overlapped); }static inline long interlocked_increment(long volatile *addr){ return BOOST_INTERLOCKED_INCREMENT(addr); }static inline long interlocked_decrement(long volatile *addr){ return BOOST_INTERLOCKED_DECREMENT(addr); }static inline long interlocked_compare_exchange(long volatile *addr, long val1, long val2){ return BOOST_INTERLOCKED_COMPARE_EXCHANGE(addr, val1, val2); }static inline long interlocked_exchange_add(long volatile* addend, long value){ return BOOST_INTERLOCKED_EXCHANGE_ADD(const_cast<long*>(addend), value); }static inline long interlocked_exchange(long volatile* addend, long value){ return BOOST_INTERLOCKED_EXCHANGE(const_cast<long*>(addend), value); }} //namespace winapi } //namespace interprocess} //namespace boost #include <boost/interprocess/detail/config_end.hpp>#endif //#ifdef BOOST_INTERPROCESS_WIN32_SYNC_PRIMITIVES_HPP
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?