diff --git a/doc/interprocess.qbk b/doc/interprocess.qbk index c74a9af..4b8f5ae 100644 --- a/doc/interprocess.qbk +++ b/doc/interprocess.qbk @@ -6650,6 +6650,12 @@ when using the library and that path will be used to place shared memory files. [endsect] +[section:boost:use_windows_h BOOST_USE_WINDOWS_H support] + +If `BOOST_USE_WINDOWS_H` is defined, and other windows SDK files are included, +otherwise the library declares needed functions and structures to reduce the impact of including +those heavy headers. + [endsect] [section:notes_linux Notes for Linux users] @@ -6745,6 +6751,7 @@ thank them: * [@https://svn.boost.org/trac/boost/ticket/9835 Trac #9835 (['"Boost Interprocess fails to compile with Android NDK GCC 4.8, -Werror=unused-variable"])]. * [@https://svn.boost.org/trac/boost/ticket/9911 Trac #9911 (['"get_tmp_base_dir(...) failure"])]. * [@https://svn.boost.org/trac/boost/ticket/9946 Trac #9946 (['"ret_ptr uninitialized in init_atomic_func, fini_atomic_func"])]. + * [@https://svn.boost.org/trac/boost/ticket/10021 Trac #10021 (['"Interprocess and BOOST_USE_WINDOWS_H"])]. * [@https://github.com/boostorg/interprocess/pull/2 GitHub #2] (['"Provide support for the Cray C++ compiler. The Cray compiler defines __GNUC__"]]). * [@https://github.com/boostorg/interprocess/pull/3 GitHub #3] (['"Fix/mingw interprocess_exception throw in file_wrapper::priv_open_or_create"]]). @@ -6761,6 +6768,12 @@ thank them: * Added `BOOST_INTERPROCESS_SHARED_DIR_PATH` option to define the shared directory used to place shared memory objects when implemented as memory mapped files. +* Added support for `BOOST_USE_WINDOWS_H`. When this macro is defined Interprocess does not declare + used Windows API function and types, includes all needed windows SDK headers and uses types and + functions declared by the Windows SDK. + +* Added `get_size` to [classref ::boost:interprocess:windows_shared_memory]. + [endsect] [section:release_notes_boost_1_55_00 Boost 1.55 Release] diff --git a/include/boost/interprocess/detail/os_file_functions.hpp b/include/boost/interprocess/detail/os_file_functions.hpp index f4d4149..edd42ad 100644 --- a/include/boost/interprocess/detail/os_file_functions.hpp +++ b/include/boost/interprocess/detail/os_file_functions.hpp @@ -270,7 +270,7 @@ inline bool delete_subdirectories_recursive void * hFile; // Handle to directory std::string strFilePath; // Filepath std::string strPattern; // Pattern - winapi::win32_find_data_t FileInformation; // File information + winapi::win32_find_data FileInformation; // File information //Find all files and directories strPattern = refcstrRootDirectory + "\\*.*"; @@ -338,7 +338,7 @@ template inline bool for_each_file_in_dir(const char *dir, Function f) { void * hFile; // Handle to directory - winapi::win32_find_data_t FileInformation; // File information + winapi::win32_find_data FileInformation; // File information //Get base directory std::string str(dir); diff --git a/include/boost/interprocess/detail/win32_api.hpp b/include/boost/interprocess/detail/win32_api.hpp index 36aaa6f..d287558 100644 --- a/include/boost/interprocess/detail/win32_api.hpp +++ b/include/boost/interprocess/detail/win32_api.hpp @@ -24,6 +24,12 @@ #include #include +#ifdef BOOST_USE_WINDOWS_H +#include +#include +#include +#include +#endif #if defined(_MSC_VER) # pragma once @@ -41,9 +47,943 @@ # error "This file can only be included in Windows OS" #endif +////////////////////////////////////////////////////////////////////////////// +// +// Declaration of Windows structures or typedefs if BOOST_USE_WINDOWS_H is used +// +////////////////////////////////////////////////////////////////////////////// + +namespace boost { +namespace interprocess { +namespace winapi { + +//Own defines +static const unsigned long MaxPath = 260; + +#ifndef BOOST_USE_WINDOWS_H + +struct GUID_BIPC +{ + unsigned long Data1; + unsigned short Data2; + unsigned short Data3; + unsigned char Data4[8]; +}; + +#pragma warning (push) +#pragma warning (disable : 4201) // nonstandard extension used + +struct decimal +{ + unsigned short wReserved; + union { + struct { + unsigned char scale; + unsigned char sign; + }; + unsigned short signscale; + }; + unsigned long Hi32; + union { + struct { + unsigned long Lo32; + unsigned long Mid32; + }; + unsigned __int64 Lo64; + }; +}; + +typedef unsigned short *bstr; + + +struct wchar_variant +{ + union + { + struct + { + unsigned short vt; + unsigned short wReserved1; + unsigned short wReserved2; + unsigned short wReserved3; + union + { + bstr bstrVal; + struct + { + void* pvRecord; + void* pRecInfo; + }; + }; + }; + decimal decVal; + }; +}; + +#pragma warning (pop) + + + + + + + + + + + + + + + + + +struct IUnknown_BIPC +{ + public: + virtual long __stdcall QueryInterface( + const GUID_BIPC &riid, // [in] + void **ppvObject) = 0; // [iid_is][out] + + virtual unsigned long __stdcall AddRef (void) = 0; + virtual unsigned long __stdcall Release(void) = 0; +}; + +struct IWbemClassObject_BIPC : public IUnknown_BIPC +{ + public: + virtual long __stdcall GetQualifierSet( + /* [out] */ void **ppQualSet) = 0; + + virtual long __stdcall Get( + /* [string][in] */ const bstr wszName, + /* [in] */ long lFlags, + /* [unique][in][out] */ wchar_variant *pVal, + /* [unique][in][out] */ long *pType, + /* [unique][in][out] */ long *plFlavor) = 0; + + virtual long __stdcall Put( + /* [string][in] */ const bstr wszName, + /* [in] */ long lFlags, + /* [in] */ wchar_variant *pVal, + /* [in] */ long Type) = 0; + + virtual long __stdcall Delete( + /* [string][in] */ const bstr wszName) = 0; + + virtual long __stdcall GetNames( + /* [string][in] */ const bstr wszQualifierName, + /* [in] */ long lFlags, + /* [in] */ wchar_variant *pQualifierVal, + /* [out] */ void * *pNames) = 0; + + virtual long __stdcall BeginEnumeration( + /* [in] */ long lEnumFlags) = 0; + + virtual long __stdcall Next( + /* [in] */ long lFlags, + /* [unique][in][out] */ bstr *strName, + /* [unique][in][out] */ wchar_variant *pVal, + /* [unique][in][out] */ long *pType, + /* [unique][in][out] */ long *plFlavor) = 0; + + virtual long __stdcall EndEnumeration( void) = 0; + + virtual long __stdcall GetPropertyQualifierSet( + /* [string][in] */ const bstr wszProperty, + /* [out] */ void **ppQualSet) = 0; + + virtual long __stdcall Clone( + /* [out] */ IWbemClassObject_BIPC **ppCopy) = 0; + + virtual long __stdcall GetObjectText( + /* [in] */ long lFlags, + /* [out] */ bstr *pstrObjectText) = 0; + + virtual long __stdcall SpawnDerivedClass( + /* [in] */ long lFlags, + /* [out] */ IWbemClassObject_BIPC **ppNewClass) = 0; + + virtual long __stdcall SpawnInstance( + /* [in] */ long lFlags, + /* [out] */ IWbemClassObject_BIPC **ppNewInstance) = 0; + + virtual long __stdcall CompareTo( + /* [in] */ long lFlags, + /* [in] */ IWbemClassObject_BIPC *pCompareTo) = 0; + + virtual long __stdcall GetPropertyOrigin( + /* [string][in] */ const bstr wszName, + /* [out] */ bstr *pstrClassName) = 0; + + virtual long __stdcall InheritsFrom( + /* [in] */ const bstr strAncestor) = 0; + + virtual long __stdcall GetMethod( + /* [string][in] */ const bstr wszName, + /* [in] */ long lFlags, + /* [out] */ IWbemClassObject_BIPC **ppInSignature, + /* [out] */ IWbemClassObject_BIPC **ppOutSignature) = 0; + + virtual long __stdcall PutMethod( + /* [string][in] */ const bstr wszName, + /* [in] */ long lFlags, + /* [in] */ IWbemClassObject_BIPC *pInSignature, + /* [in] */ IWbemClassObject_BIPC *pOutSignature) = 0; + + virtual long __stdcall DeleteMethod( + /* [string][in] */ const bstr wszName) = 0; + + virtual long __stdcall BeginMethodEnumeration( + /* [in] */ long lEnumFlags) = 0; + + virtual long __stdcall NextMethod( + /* [in] */ long lFlags, + /* [unique][in][out] */ bstr *pstrName, + /* [unique][in][out] */ IWbemClassObject_BIPC **ppInSignature, + /* [unique][in][out] */ IWbemClassObject_BIPC **ppOutSignature) = 0; + + virtual long __stdcall EndMethodEnumeration( void) = 0; + + virtual long __stdcall GetMethodQualifierSet( + /* [string][in] */ const bstr wszMethod, + /* [out] */ void **ppQualSet) = 0; + + virtual long __stdcall GetMethodOrigin( + /* [string][in] */ const bstr wszMethodName, + /* [out] */ bstr *pstrClassName) = 0; + +}; + +struct IWbemContext_BIPC : public IUnknown_BIPC +{ +public: + virtual long __stdcall Clone( + /* [out] */ IWbemContext_BIPC **ppNewCopy) = 0; + + virtual long __stdcall GetNames( + /* [in] */ long lFlags, + /* [out] */ void * *pNames) = 0; + + virtual long __stdcall BeginEnumeration( + /* [in] */ long lFlags) = 0; + + virtual long __stdcall Next( + /* [in] */ long lFlags, + /* [out] */ bstr *pstrName, + /* [out] */ wchar_variant *pValue) = 0; + + virtual long __stdcall EndEnumeration( void) = 0; + + virtual long __stdcall SetValue( + /* [string][in] */ const bstr wszName, + /* [in] */ long lFlags, + /* [in] */ wchar_variant *pValue) = 0; + + virtual long __stdcall GetValue( + /* [string][in] */ const bstr wszName, + /* [in] */ long lFlags, + /* [out] */ wchar_variant *pValue) = 0; + + virtual long __stdcall DeleteValue( + /* [string][in] */ const bstr wszName, + /* [in] */ long lFlags) = 0; + + virtual long __stdcall DeleteAll( void) = 0; + +}; + + +struct IEnumWbemClassObject_BIPC : public IUnknown_BIPC +{ +public: + virtual long __stdcall Reset( void) = 0; + + virtual long __stdcall Next( + /* [in] */ long lTimeout, + /* [in] */ unsigned long uCount, + /* [length_is][size_is][out] */ IWbemClassObject_BIPC **apObjects, + /* [out] */ unsigned long *puReturned) = 0; + + virtual long __stdcall NextAsync( + /* [in] */ unsigned long uCount, + /* [in] */ void *pSink) = 0; + + virtual long __stdcall Clone( + /* [out] */ void **ppEnum) = 0; + + virtual long __stdcall Skip( + /* [in] */ long lTimeout, + /* [in] */ unsigned long nCount) = 0; + +}; + +struct IWbemServices_BIPC : public IUnknown_BIPC +{ +public: + virtual long __stdcall OpenNamespace( + /* [in] */ const bstr strNamespace, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [unique][in][out] */ void **ppWorkingNamespace, + /* [unique][in][out] */ void **ppResult) = 0; + + virtual long __stdcall CancelAsyncCall( + /* [in] */ void *pSink) = 0; + + virtual long __stdcall QueryObjectSink( + /* [in] */ long lFlags, + /* [out] */ void **ppResponseHandler) = 0; + + virtual long __stdcall GetObject( + /* [in] */ const bstr strObjectPath, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [unique][in][out] */ void **ppObject, + /* [unique][in][out] */ void **ppCallResult) = 0; + + virtual long __stdcall GetObjectAsync( + /* [in] */ const bstr strObjectPath, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall PutClass( + /* [in] */ IWbemClassObject_BIPC *pObject, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [unique][in][out] */ void **ppCallResult) = 0; + + virtual long __stdcall PutClassAsync( + /* [in] */ IWbemClassObject_BIPC *pObject, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall DeleteClass( + /* [in] */ const bstr strClass, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [unique][in][out] */ void **ppCallResult) = 0; + + virtual long __stdcall DeleteClassAsync( + /* [in] */ const bstr strClass, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall CreateClassEnum( + /* [in] */ const bstr strSuperclass, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [out] */ void **ppEnum) = 0; + + virtual long __stdcall CreateClassEnumAsync( + /* [in] */ const bstr strSuperclass, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall PutInstance( + /* [in] */ void *pInst, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [unique][in][out] */ void **ppCallResult) = 0; + + virtual long __stdcall PutInstanceAsync( + /* [in] */ void *pInst, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall DeleteInstance( + /* [in] */ const bstr strObjectPath, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [unique][in][out] */ void **ppCallResult) = 0; + + virtual long __stdcall DeleteInstanceAsync( + /* [in] */ const bstr strObjectPath, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall CreateInstanceEnum( + /* [in] */ const bstr strFilter, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [out] */ void **ppEnum) = 0; + + virtual long __stdcall CreateInstanceEnumAsync( + /* [in] */ const bstr strFilter, + /* [in] */ long lFlags, + /* [in] */ void *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall ExecQuery( + /* [in] */ const bstr strQueryLanguage, + /* [in] */ const bstr strQuery, + /* [in] */ long lFlags, + /* [in] */ IWbemContext_BIPC *pCtx, + /* [out] */ IEnumWbemClassObject_BIPC **ppEnum) = 0; + + virtual long __stdcall ExecQueryAsync( + /* [in] */ const bstr strQueryLanguage, + /* [in] */ const bstr strQuery, + /* [in] */ long lFlags, + /* [in] */ IWbemContext_BIPC *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall ExecNotificationQuery( + /* [in] */ const bstr strQueryLanguage, + /* [in] */ const bstr strQuery, + /* [in] */ long lFlags, + /* [in] */ IWbemContext_BIPC *pCtx, + /* [out] */ void **ppEnum) = 0; + + virtual long __stdcall ExecNotificationQueryAsync( + /* [in] */ const bstr strQueryLanguage, + /* [in] */ const bstr strQuery, + /* [in] */ long lFlags, + /* [in] */ IWbemContext_BIPC *pCtx, + /* [in] */ void *pResponseHandler) = 0; + + virtual long __stdcall ExecMethod( + /* [in] */ const bstr strObjectPath, + /* [in] */ const bstr strMethodName, + /* [in] */ long lFlags, + /* [in] */ IWbemContext_BIPC *pCtx, + /* [in] */ IWbemClassObject_BIPC *pInParams, + /* [unique][in][out] */ IWbemClassObject_BIPC **ppOutParams, + /* [unique][in][out] */ void **ppCallResult) = 0; + + virtual long __stdcall ExecMethodAsync( + /* [in] */ const bstr strObjectPath, + /* [in] */ const bstr strMethodName, + /* [in] */ long lFlags, + /* [in] */ IWbemContext_BIPC *pCtx, + /* [in] */ IWbemClassObject_BIPC *pInParams, + /* [in] */ void *pResponseHandler) = 0; + +}; + +struct IWbemLocator_BIPC : public IUnknown_BIPC +{ +public: + virtual long __stdcall ConnectServer( + /* [in] */ const bstr strNetworkResource, + /* [in] */ const bstr strUser, + /* [in] */ const bstr strPassword, + /* [in] */ const bstr strLocale, + /* [in] */ long lSecurityFlags, + /* [in] */ const bstr strAuthority, + /* [in] */ void *pCtx, + /* [out] */ IWbemServices_BIPC **ppNamespace) = 0; + +}; + +struct interprocess_overlapped +{ + unsigned long *internal; + unsigned long *internal_high; + union { + struct { + unsigned long offset; + unsigned long offset_high; + }dummy; + void *pointer; + }; + + void *h_event; +}; + + +struct interprocess_filetime +{ + unsigned long dwLowDateTime; + unsigned long dwHighDateTime; +}; + +struct win32_find_data +{ + unsigned long dwFileAttributes; + interprocess_filetime ftCreationTime; + interprocess_filetime ftLastAccessTime; + interprocess_filetime ftLastWriteTime; + unsigned long nFileSizeHigh; + unsigned long nFileSizeLow; + unsigned long dwReserved0; + unsigned long dwReserved1; + char cFileName[MaxPath]; + char cAlternateFileName[14]; +}; + +struct interprocess_security_attributes +{ + unsigned long nLength; + void *lpSecurityDescriptor; + int bInheritHandle; +}; + +struct system_info { + union { + unsigned long dwOemId; // Obsolete field...do not use + struct { + unsigned short wProcessorArchitecture; + unsigned short wReserved; + } dummy; + }; + unsigned long dwPageSize; + void * lpMinimumApplicationAddress; + void * lpMaximumApplicationAddress; + unsigned long * dwActiveProcessorMask; + unsigned long dwNumberOfProcessors; + unsigned long dwProcessorType; + unsigned long dwAllocationGranularity; + unsigned short wProcessorLevel; + unsigned short wProcessorRevision; +}; + +struct interprocess_acl +{ + unsigned char AclRevision; + unsigned char Sbz1; + unsigned short AclSize; + unsigned short AceCount; + unsigned short Sbz2; +}; + +struct interprocess_security_descriptor +{ + unsigned char Revision; + unsigned char Sbz1; + unsigned short Control; + void *Owner; + void *Group; + interprocess_acl *Sacl; + interprocess_acl *Dacl; +}; + +struct interprocess_by_handle_file_information +{ + unsigned long dwFileAttributes; + interprocess_filetime ftCreationTime; + interprocess_filetime ftLastAccessTime; + interprocess_filetime ftLastWriteTime; + unsigned long dwVolumeSerialNumber; + unsigned long nFileSizeHigh; + unsigned long nFileSizeLow; + unsigned long nNumberOfLinks; + unsigned long nFileIndexHigh; + unsigned long nFileIndexLow; +}; + +struct interprocess_eventlogrecord +{ + unsigned long Length; // Length of full record + unsigned long Reserved; // Used by the service + unsigned long RecordNumber; // Absolute record number + unsigned long TimeGenerated; // Seconds since 1-1-1970 + unsigned long TimeWritten; // Seconds since 1-1-1970 + unsigned long EventID; + unsigned short EventType; + unsigned short NumStrings; + unsigned short EventCategory; + unsigned short ReservedFlags; // For use with paired events (auditing) + unsigned long ClosingRecordNumber; // For use with paired events (auditing) + unsigned long StringOffset; // Offset from beginning of record + unsigned long UserSidLength; + unsigned long UserSidOffset; + unsigned long DataLength; + unsigned long DataOffset; // Offset from beginning of record + // + // Then follow: + // + // wchar_t SourceName[] + // wchar_t Computername[] + // SID UserSid + // wchar_t Strings[] + // BYTE Data[] + // CHAR Pad[] + // unsigned long Length; + // +}; + +union large_integer +{ + __int64 QuadPart; +}; + +struct hinstance_struct { int unused; }; +typedef hinstance_struct *hmodule; + +struct hkey_struct; +typedef hkey_struct *hkey; + +#else //#ifndef BOOST_USE_WINDOWS_H + +typedef GUID GUID_BIPC; +typedef VARIANT wchar_variant; + +typedef IUnknown IUnknown_BIPC; + +typedef IWbemClassObject IWbemClassObject_BIPC; + +typedef IWbemContext IWbemContext_BIPC; + +typedef IEnumWbemClassObject IEnumWbemClassObject_BIPC; + +typedef IWbemServices IWbemServices_BIPC; + +typedef IWbemLocator IWbemLocator_BIPC; + +typedef OVERLAPPED interprocess_overlapped; + +typedef FILETIME interprocess_filetime; + +typedef WIN32_FIND_DATA win32_find_data; + +typedef SECURITY_ATTRIBUTES interprocess_security_attributes; + +typedef SYSTEM_INFO system_info; + +typedef ACL interprocess_acl; + +typedef SECURITY_DESCRIPTOR interprocess_security_descriptor; + +typedef BY_HANDLE_FILE_INFORMATION interprocess_by_handle_file_information; + +typedef EVENTLOGRECORD interprocess_eventlogrecord; + +typedef LARGE_INTEGER large_integer; + +typedef HMODULE hmodule; + +typedef HKEY hkey; + +typedef BSTR bstr; + +#endif //#ifndef BOOST_USE_WINDOWS_H + +////////////////////////////////////////////////////////////////////////////// +// +// Nt native structures +// +////////////////////////////////////////////////////////////////////////////// + +struct interprocess_semaphore_basic_information +{ + unsigned int count; // current semaphore count + unsigned int limit; // max semaphore count +}; + +struct interprocess_section_basic_information +{ + void * base_address; + unsigned long section_attributes; + __int64 section_size; +}; + +struct file_rename_information_t { + int Replace; + void *RootDir; + unsigned long FileNameLength; + wchar_t FileName[1]; +}; + +struct unicode_string_t { + unsigned short Length; + unsigned short MaximumLength; + wchar_t *Buffer; +}; + +struct object_attributes_t { + unsigned long Length; + void * RootDirectory; + unicode_string_t *ObjectName; + unsigned long Attributes; + void *SecurityDescriptor; + void *SecurityQualityOfService; +}; + +struct io_status_block_t { + union { + long Status; + void *Pointer; + }; + + unsigned long *Information; +}; + +union system_timeofday_information +{ + struct data_t + { + __int64 liKeBootTime; + __int64 liKeSystemTime; + __int64 liExpTimeZoneBias; + unsigned long uCurrentTimeZoneId; + unsigned long dwReserved; + unsigned __int64 ullBootTimeBias; + unsigned __int64 ullSleepTimeBias; + } data; + unsigned char Reserved1[sizeof(data_t)]; +}; + +static const long BootstampLength = sizeof(__int64); +static const long BootAndSystemstampLength = sizeof(__int64)*2; +static const long SystemTimeOfDayInfoLength = sizeof(system_timeofday_information::data_t); + +struct object_name_information_t +{ + unicode_string_t Name; + wchar_t NameBuffer[1]; +}; + +enum file_information_class_t { + file_directory_information = 1, + file_full_directory_information, + file_both_directory_information, + file_basic_information, + file_standard_information, + file_internal_information, + file_ea_information, + file_access_information, + file_name_information, + file_rename_information, + file_link_information, + file_names_information, + file_disposition_information, + file_position_information, + file_full_ea_information, + file_mode_information, + file_alignment_information, + file_all_information, + file_allocation_information, + file_end_of_file_information, + file_alternate_name_information, + file_stream_information, + file_pipe_information, + file_pipe_local_information, + file_pipe_remote_information, + file_mailslot_query_information, + file_mailslot_set_information, + file_compression_information, + file_copy_on_write_information, + file_completion_information, + file_move_cluster_information, + file_quota_information, + file_reparse_point_information, + file_network_open_information, + file_object_id_information, + file_tracking_information, + file_ole_directory_information, + file_content_index_information, + file_inherit_content_index_information, + file_ole_information, + file_maximum_information +}; + +enum semaphore_information_class { + semaphore_basic_information = 0 +}; + + +enum system_information_class { + system_basic_information = 0, + system_performance_information = 2, + system_time_of_day_information = 3, + system_process_information = 5, + system_processor_performance_information = 8, + system_interrupt_information = 23, + system_exception_information = 33, + system_registry_quota_information = 37, + system_lookaside_information = 45 +}; + +enum object_information_class +{ + object_basic_information, + object_name_information, + object_type_information, + object_all_information, + object_data_information +}; + +enum section_information_class +{ + section_basic_information, + section_image_information +}; + +////////////////////////////////////////////////////////////////////////////// +// +// Forward declaration of winapi +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_USE_WINDOWS_H + +//Kernel32.dll + +//Some windows API declarations +extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId(); +extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(); +extern "C" __declspec(dllimport) int __stdcall GetProcessTimes + ( void *hProcess, interprocess_filetime* lpCreationTime + , interprocess_filetime *lpExitTime,interprocess_filetime *lpKernelTime + , interprocess_filetime *lpUserTime ); +extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long); +extern "C" __declspec(dllimport) unsigned long __stdcall GetTickCount(void); +extern "C" __declspec(dllimport) int __stdcall SwitchToThread(); +extern "C" __declspec(dllimport) unsigned long __stdcall GetLastError(); +extern "C" __declspec(dllimport) void __stdcall SetLastError(unsigned long); +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) long __stdcall GetFileType(void *hFile); +extern "C" __declspec(dllimport) void *__stdcall FindFirstFileA(const char *lpFileName, win32_find_data *lpFindFileData); +extern "C" __declspec(dllimport) int __stdcall FindNextFileA(void *hFindFile, win32_find_data *lpFindFileData); +extern "C" __declspec(dllimport) int __stdcall FindClose(void *hFindFile); +//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) void __stdcall GetSystemInfo (struct system_info *); +extern "C" __declspec(dllimport) int __stdcall FlushViewOfFile (void *, std::size_t); +extern "C" __declspec(dllimport) int __stdcall VirtualUnlock (void *, std::size_t); +extern "C" __declspec(dllimport) int __stdcall VirtualProtect (void *, std::size_t, unsigned long, unsigned long *); +extern "C" __declspec(dllimport) int __stdcall FlushFileBuffers (void *); +extern "C" __declspec(dllimport) int __stdcall GetFileSizeEx (void *, large_integer *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) unsigned long __stdcall GetFileAttributesA(const char *); +extern "C" __declspec(dllimport) int __stdcall CreateDirectoryA(const char *, interprocess_security_attributes*); +extern "C" __declspec(dllimport) int __stdcall RemoveDirectoryA(const char *lpPathName); +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 *, large_integer distance, large_integer *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 ReadFile(void *hnd, void *buffer, unsigned long bytes_to_read, unsigned long *bytes_read, 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); +extern "C" __declspec(dllimport) hmodule __stdcall LoadLibraryA(const char *); +extern "C" __declspec(dllimport) int __stdcall FreeLibrary(hmodule); +extern "C" __declspec(dllimport) void *__stdcall GetProcAddress(void *, const char*); +extern "C" __declspec(dllimport) hmodule __stdcall GetModuleHandleA(const char*); +extern "C" __declspec(dllimport) void *__stdcall GetFileInformationByHandle(void *, interprocess_by_handle_file_information*); + +//Advapi32.dll +extern "C" __declspec(dllimport) long __stdcall RegOpenKeyExA(hkey, const char *, unsigned long, unsigned long, hkey*); +extern "C" __declspec(dllimport) long __stdcall RegQueryValueExA(hkey, const char *, unsigned long*, unsigned long*, unsigned char *, unsigned long*); +extern "C" __declspec(dllimport) long __stdcall RegCloseKey(hkey); + +//Ole32.dll +extern "C" __declspec(dllimport) long __stdcall CoInitializeEx(void *pvReserved, unsigned long dwCoInit); +extern "C" __declspec(dllimport) long __stdcall CoInitializeSecurity( + void* pSecDesc, + long cAuthSvc, + void * asAuthSvc, + void *pReserved1, + unsigned long dwAuthnLevel, + unsigned long dwImpLevel, + void *pAuthList, + unsigned long dwCapabilities, + void *pReserved3 ); + + extern "C" __declspec(dllimport) long __stdcall CoSetProxyBlanket( + IUnknown_BIPC *pProxy, + unsigned long dwAuthnSvc, + unsigned long dwAuthzSvc, + wchar_t *pServerPrincName, + unsigned long dwAuthnLevel, + unsigned long dwImpLevel, + void *pAuthInfo, + unsigned long dwCapabilities); +extern "C" __declspec(dllimport) long __stdcall CoCreateInstance(const GUID_BIPC & rclsid, IUnknown_BIPC *pUnkOuter, + unsigned long dwClsContext, const GUID_BIPC & riid, void** ppv); +extern "C" __declspec(dllimport) void __stdcall CoUninitialize(void); + +//OleAut32.dll +extern "C" __declspec(dllimport) long __stdcall VariantClear(wchar_variant * pvarg); + +//Shell32.dll +extern "C" __declspec(dllimport) int __stdcall SHGetSpecialFolderPathA + (void* hwnd, const char *pszPath, int csidl, int fCreate); + +extern "C" __declspec(dllimport) int __stdcall SHGetFolderPathA(void *hwnd, int csidl, void *hToken, unsigned long dwFlags, const char *pszPath); + +//EventLog access functions + +extern "C" __declspec(dllimport) void* __stdcall OpenEventLogA + (const char* lpUNCServerName, const char* lpSourceName); + +extern "C" __declspec(dllimport) int __stdcall CloseEventLog(void *hEventLog); + +extern "C" __declspec(dllimport) int __stdcall ReadEventLogA + (void *hEventLog, + unsigned long dwReadFlags, + unsigned long dwRecordOffset, + void *lpBuffer, + unsigned long nNumberOfBytesToRead, + unsigned long *pnBytesRead, + unsigned long *pnMinNumberOfBytesNeeded + ); + +#endif //#ifndef BOOST_USE_WINDOWS_H + +//kernel32.dll +typedef int (__stdcall *QueryPerformanceCounter_t) (__int64 *lpPerformanceCount); +typedef int (__stdcall *QueryPerformanceFrequency_t)(__int64 *lpFrequency); + +//ntdll.dll +typedef long (__stdcall *NtDeleteFile_t)(object_attributes_t *ObjectAttributes); +typedef long (__stdcall *NtSetInformationFile_t)(void *FileHandle, io_status_block_t *IoStatusBlock, void *FileInformation, unsigned long Length, int FileInformationClass ); +typedef long (__stdcall *NtOpenFile)(void **FileHandle, unsigned long DesiredAccess, object_attributes_t *ObjectAttributes + , io_status_block_t *IoStatusBlock, unsigned long ShareAccess, unsigned long Length, unsigned long OpenOptions); +typedef long (__stdcall *NtQuerySystemInformation_t)(int, void*, unsigned long, unsigned long *); +typedef long (__stdcall *NtQueryObject_t)(void*, object_information_class, void *, unsigned long, unsigned long *); +typedef long (__stdcall *NtQuerySemaphore_t)(void*, unsigned int info_class, interprocess_semaphore_basic_information *pinfo, unsigned int info_size, unsigned int *ret_len); +typedef long (__stdcall *NtQuerySection_t)(void*, section_information_class, interprocess_section_basic_information *pinfo, unsigned long info_size, unsigned long *ret_len); +typedef long (__stdcall *NtQueryInformationFile_t)(void *,io_status_block_t *,void *, long, int); +typedef long (__stdcall *NtOpenFile_t)(void*,unsigned long ,object_attributes_t*,io_status_block_t*,unsigned long,unsigned long); +typedef long (__stdcall *NtClose_t) (void*); +typedef long (__stdcall *NtQueryTimerResolution_t) (unsigned long* LowestResolution, unsigned long* HighestResolution, unsigned long* CurrentResolution); +typedef long (__stdcall *NtSetTimerResolution_t) (unsigned long RequestedResolution, int Set, unsigned long* ActualResolution); + +} //namespace winapi { +} //namespace interprocess { +} //namespace boost { + +////////////////////////////////////////////////////////////////////////////// +// +// Forward declaration of constants +// +////////////////////////////////////////////////////////////////////////////// -//The structures used in Interprocess with the -//same binary interface as windows ones namespace boost { namespace interprocess { namespace winapi { @@ -173,14 +1113,8 @@ static const unsigned long security_descriptor_revision = 1; const unsigned long max_record_buffer_size = 0x10000L; // 64K const unsigned long max_path = 260; -//Own defines -static const long SystemTimeOfDayInfoLength = 48; -static const long BootAndSystemstampLength = 16; -static const long BootstampLength = 8; -static const unsigned long MaxPath = 260; - //Keys -static void * const hkey_local_machine = (void*)(unsigned long*)(long)(0x80000002); +static const hkey hkey_local_machine = (hkey)(unsigned long*)(long)(0x80000002); static unsigned long key_query_value = 0x0001; //COM API @@ -204,6 +1138,7 @@ const unsigned long COINIT_MULTITHREADED_BIPC = 0x0; const unsigned long COINIT_DISABLE_OLE1DDE_BIPC = 0x4; const unsigned long COINIT_SPEED_OVER_MEMORY_BIPC = 0x4; + //If the user needs to change default COM initialization model, //it can define BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL to one of these: // @@ -220,817 +1155,19 @@ const unsigned long COINIT_SPEED_OVER_MEMORY_BIPC = 0x4; #error "Wrong value for BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL macro" #endif -} //namespace winapi { -} //namespace interprocess { -} //namespace boost { - - -namespace boost { -namespace interprocess { -namespace winapi { - -struct GUID_BIPC -{ - unsigned long Data1; - unsigned short Data2; - unsigned short Data3; - unsigned char Data4[8]; -}; - const GUID_BIPC CLSID_WbemAdministrativeLocator = { 0xcb8555cc, 0x9128, 0x11d1, {0xad, 0x9b, 0x00, 0xc0, 0x4f, 0xd8, 0xfd, 0xff}}; const GUID_BIPC IID_IUnknown = { 0x00000000, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}; -struct wchar_variant -{ - unsigned long long dummy; - union value_t{ - wchar_t *pbstrVal; - unsigned long long dummy; - } value; -}; - -struct IUnknown_BIPC -{ - public: - virtual long __stdcall QueryInterface( - const GUID_BIPC &riid, // [in] - void **ppvObject) = 0; // [iid_is][out] - - virtual unsigned long __stdcall AddRef (void) = 0; - virtual unsigned long __stdcall Release(void) = 0; -}; - -struct IWbemClassObject_BIPC : public IUnknown_BIPC -{ - public: - virtual long __stdcall GetQualifierSet( - /* [out] */ void **ppQualSet) = 0; - - virtual long __stdcall Get( - /* [string][in] */ const wchar_t * wszName, - /* [in] */ long lFlags, - /* [unique][in][out] */ wchar_variant *pVal, - /* [unique][in][out] */ long *pType, - /* [unique][in][out] */ long *plFlavor) = 0; - - virtual long __stdcall Put( - /* [string][in] */ const wchar_t * wszName, - /* [in] */ long lFlags, - /* [in] */ wchar_variant *pVal, - /* [in] */ long Type) = 0; - - virtual long __stdcall Delete( - /* [string][in] */ const wchar_t * wszName) = 0; - - virtual long __stdcall GetNames( - /* [string][in] */ const wchar_t * wszQualifierName, - /* [in] */ long lFlags, - /* [in] */ wchar_variant *pQualifierVal, - /* [out] */ void * *pNames) = 0; - - virtual long __stdcall BeginEnumeration( - /* [in] */ long lEnumFlags) = 0; - - virtual long __stdcall Next( - /* [in] */ long lFlags, - /* [unique][in][out] */ wchar_t * *strName, - /* [unique][in][out] */ wchar_variant *pVal, - /* [unique][in][out] */ long *pType, - /* [unique][in][out] */ long *plFlavor) = 0; - - virtual long __stdcall EndEnumeration( void) = 0; - - virtual long __stdcall GetPropertyQualifierSet( - /* [string][in] */ const wchar_t * wszProperty, - /* [out] */ void **ppQualSet) = 0; - - virtual long __stdcall Clone( - /* [out] */ IWbemClassObject_BIPC **ppCopy) = 0; - - virtual long __stdcall GetObjectText( - /* [in] */ long lFlags, - /* [out] */ wchar_t * *pstrObjectText) = 0; - - virtual long __stdcall SpawnDerivedClass( - /* [in] */ long lFlags, - /* [out] */ IWbemClassObject_BIPC **ppNewClass) = 0; - - virtual long __stdcall SpawnInstance( - /* [in] */ long lFlags, - /* [out] */ IWbemClassObject_BIPC **ppNewInstance) = 0; - - virtual long __stdcall CompareTo( - /* [in] */ long lFlags, - /* [in] */ IWbemClassObject_BIPC *pCompareTo) = 0; - - virtual long __stdcall GetPropertyOrigin( - /* [string][in] */ const wchar_t * wszName, - /* [out] */ wchar_t * *pstrClassName) = 0; - - virtual long __stdcall InheritsFrom( - /* [in] */ const wchar_t * strAncestor) = 0; - - virtual long __stdcall GetMethod( - /* [string][in] */ const wchar_t * wszName, - /* [in] */ long lFlags, - /* [out] */ IWbemClassObject_BIPC **ppInSignature, - /* [out] */ IWbemClassObject_BIPC **ppOutSignature) = 0; - - virtual long __stdcall PutMethod( - /* [string][in] */ const wchar_t * wszName, - /* [in] */ long lFlags, - /* [in] */ IWbemClassObject_BIPC *pInSignature, - /* [in] */ IWbemClassObject_BIPC *pOutSignature) = 0; - - virtual long __stdcall DeleteMethod( - /* [string][in] */ const wchar_t * wszName) = 0; - - virtual long __stdcall BeginMethodEnumeration( - /* [in] */ long lEnumFlags) = 0; - - virtual long __stdcall NextMethod( - /* [in] */ long lFlags, - /* [unique][in][out] */ wchar_t * *pstrName, - /* [unique][in][out] */ IWbemClassObject_BIPC **ppInSignature, - /* [unique][in][out] */ IWbemClassObject_BIPC **ppOutSignature) = 0; - - virtual long __stdcall EndMethodEnumeration( void) = 0; - - virtual long __stdcall GetMethodQualifierSet( - /* [string][in] */ const wchar_t * wszMethod, - /* [out] */ void **ppQualSet) = 0; - - virtual long __stdcall GetMethodOrigin( - /* [string][in] */ const wchar_t * wszMethodName, - /* [out] */ wchar_t * *pstrClassName) = 0; - -}; - -struct IWbemContext_BIPC : public IUnknown_BIPC -{ -public: - virtual long __stdcall Clone( - /* [out] */ IWbemContext_BIPC **ppNewCopy) = 0; - - virtual long __stdcall GetNames( - /* [in] */ long lFlags, - /* [out] */ void * *pNames) = 0; - - virtual long __stdcall BeginEnumeration( - /* [in] */ long lFlags) = 0; - - virtual long __stdcall Next( - /* [in] */ long lFlags, - /* [out] */ wchar_t * *pstrName, - /* [out] */ wchar_variant *pValue) = 0; - - virtual long __stdcall EndEnumeration( void) = 0; - - virtual long __stdcall SetValue( - /* [string][in] */ const wchar_t * wszName, - /* [in] */ long lFlags, - /* [in] */ wchar_variant *pValue) = 0; - - virtual long __stdcall GetValue( - /* [string][in] */ const wchar_t * wszName, - /* [in] */ long lFlags, - /* [out] */ wchar_variant *pValue) = 0; - - virtual long __stdcall DeleteValue( - /* [string][in] */ const wchar_t * wszName, - /* [in] */ long lFlags) = 0; - - virtual long __stdcall DeleteAll( void) = 0; - -}; - - -struct IEnumWbemClassObject_BIPC : public IUnknown_BIPC -{ -public: - virtual long __stdcall Reset( void) = 0; - - virtual long __stdcall Next( - /* [in] */ long lTimeout, - /* [in] */ unsigned long uCount, - /* [length_is][size_is][out] */ IWbemClassObject_BIPC **apObjects, - /* [out] */ unsigned long *puReturned) = 0; - - virtual long __stdcall NextAsync( - /* [in] */ unsigned long uCount, - /* [in] */ void *pSink) = 0; - - virtual long __stdcall Clone( - /* [out] */ void **ppEnum) = 0; - - virtual long __stdcall Skip( - /* [in] */ long lTimeout, - /* [in] */ unsigned long nCount) = 0; - -}; - -struct IWbemServices_BIPC : public IUnknown_BIPC -{ -public: - virtual long __stdcall OpenNamespace( - /* [in] */ const wchar_t * strNamespace, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [unique][in][out] */ void **ppWorkingNamespace, - /* [unique][in][out] */ void **ppResult) = 0; - - virtual long __stdcall CancelAsyncCall( - /* [in] */ void *pSink) = 0; - - virtual long __stdcall QueryObjectSink( - /* [in] */ long lFlags, - /* [out] */ void **ppResponseHandler) = 0; - - virtual long __stdcall GetObject( - /* [in] */ const wchar_t * strObjectPath, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [unique][in][out] */ void **ppObject, - /* [unique][in][out] */ void **ppCallResult) = 0; - - virtual long __stdcall GetObjectAsync( - /* [in] */ const wchar_t * strObjectPath, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall PutClass( - /* [in] */ IWbemClassObject_BIPC *pObject, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [unique][in][out] */ void **ppCallResult) = 0; - - virtual long __stdcall PutClassAsync( - /* [in] */ IWbemClassObject_BIPC *pObject, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall DeleteClass( - /* [in] */ const wchar_t * strClass, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [unique][in][out] */ void **ppCallResult) = 0; - - virtual long __stdcall DeleteClassAsync( - /* [in] */ const wchar_t * strClass, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall CreateClassEnum( - /* [in] */ const wchar_t * strSuperclass, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [out] */ void **ppEnum) = 0; - - virtual long __stdcall CreateClassEnumAsync( - /* [in] */ const wchar_t * strSuperclass, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall PutInstance( - /* [in] */ void *pInst, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [unique][in][out] */ void **ppCallResult) = 0; - - virtual long __stdcall PutInstanceAsync( - /* [in] */ void *pInst, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall DeleteInstance( - /* [in] */ const wchar_t * strObjectPath, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [unique][in][out] */ void **ppCallResult) = 0; - - virtual long __stdcall DeleteInstanceAsync( - /* [in] */ const wchar_t * strObjectPath, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall CreateInstanceEnum( - /* [in] */ const wchar_t * strFilter, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [out] */ void **ppEnum) = 0; - - virtual long __stdcall CreateInstanceEnumAsync( - /* [in] */ const wchar_t * strFilter, - /* [in] */ long lFlags, - /* [in] */ void *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall ExecQuery( - /* [in] */ const wchar_t * strQueryLanguage, - /* [in] */ const wchar_t * strQuery, - /* [in] */ long lFlags, - /* [in] */ IWbemContext_BIPC *pCtx, - /* [out] */ IEnumWbemClassObject_BIPC **ppEnum) = 0; - - virtual long __stdcall ExecQueryAsync( - /* [in] */ const wchar_t * strQueryLanguage, - /* [in] */ const wchar_t * strQuery, - /* [in] */ long lFlags, - /* [in] */ IWbemContext_BIPC *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall ExecNotificationQuery( - /* [in] */ const wchar_t * strQueryLanguage, - /* [in] */ const wchar_t * strQuery, - /* [in] */ long lFlags, - /* [in] */ IWbemContext_BIPC *pCtx, - /* [out] */ void **ppEnum) = 0; - - virtual long __stdcall ExecNotificationQueryAsync( - /* [in] */ const wchar_t * strQueryLanguage, - /* [in] */ const wchar_t * strQuery, - /* [in] */ long lFlags, - /* [in] */ IWbemContext_BIPC *pCtx, - /* [in] */ void *pResponseHandler) = 0; - - virtual long __stdcall ExecMethod( - /* [in] */ const wchar_t * strObjectPath, - /* [in] */ const wchar_t * strMethodName, - /* [in] */ long lFlags, - /* [in] */ IWbemContext_BIPC *pCtx, - /* [in] */ IWbemClassObject_BIPC *pInParams, - /* [unique][in][out] */ IWbemClassObject_BIPC **ppOutParams, - /* [unique][in][out] */ void **ppCallResult) = 0; - - virtual long __stdcall ExecMethodAsync( - /* [in] */ const wchar_t * strObjectPath, - /* [in] */ const wchar_t * strMethodName, - /* [in] */ long lFlags, - /* [in] */ IWbemContext_BIPC *pCtx, - /* [in] */ IWbemClassObject_BIPC *pInParams, - /* [in] */ void *pResponseHandler) = 0; - -}; - -struct IWbemLocator_BIPC : public IUnknown_BIPC -{ -public: - virtual long __stdcall ConnectServer( - /* [in] */ const wchar_t * strNetworkResource, - /* [in] */ const wchar_t * strUser, - /* [in] */ const wchar_t * strPassword, - /* [in] */ const wchar_t * strLocale, - /* [in] */ long lSecurityFlags, - /* [in] */ const wchar_t * strAuthority, - /* [in] */ void *pCtx, - /* [out] */ IWbemServices_BIPC **ppNamespace) = 0; - -}; - -struct interprocess_overlapped -{ - unsigned long *internal; - unsigned long *internal_high; - union { - struct { - unsigned long offset; - unsigned long offset_high; - }dummy; - void *pointer; - }; - - void *h_event; -}; - -struct interprocess_semaphore_basic_information -{ - unsigned int count; // current semaphore count - unsigned int limit; // max semaphore count -}; - -struct interprocess_section_basic_information -{ - void * base_address; - unsigned long section_attributes; - __int64 section_size; -}; - -struct interprocess_filetime -{ - unsigned long dwLowDateTime; - unsigned long dwHighDateTime; -}; - -struct win32_find_data_t -{ - unsigned long dwFileAttributes; - interprocess_filetime ftCreationTime; - interprocess_filetime ftLastAccessTime; - interprocess_filetime ftLastWriteTime; - unsigned long nFileSizeHigh; - unsigned long nFileSizeLow; - unsigned long dwReserved0; - unsigned long dwReserved1; - char cFileName[MaxPath]; - char cAlternateFileName[14]; -}; - -struct interprocess_security_attributes -{ - unsigned long nLength; - void *lpSecurityDescriptor; - int bInheritHandle; -}; - -struct system_info { - union { - unsigned long dwOemId; // Obsolete field...do not use - struct { - unsigned short wProcessorArchitecture; - unsigned short wReserved; - } dummy; - }; - unsigned long dwPageSize; - void * lpMinimumApplicationAddress; - void * lpMaximumApplicationAddress; - unsigned long * dwActiveProcessorMask; - unsigned long dwNumberOfProcessors; - unsigned long dwProcessorType; - unsigned long dwAllocationGranularity; - unsigned short wProcessorLevel; - unsigned short wProcessorRevision; -}; - -struct interprocess_memory_basic_information -{ - void * BaseAddress; - void * AllocationBase; - unsigned long AllocationProtect; - unsigned long RegionSize; - unsigned long State; - unsigned long Protect; - unsigned long Type; -}; - -struct interprocess_acl -{ - unsigned char AclRevision; - unsigned char Sbz1; - unsigned short AclSize; - unsigned short AceCount; - unsigned short Sbz2; -}; - -typedef struct _interprocess_security_descriptor -{ - unsigned char Revision; - unsigned char Sbz1; - unsigned short Control; - void *Owner; - void *Group; - interprocess_acl *Sacl; - interprocess_acl *Dacl; -} interprocess_security_descriptor; - -enum file_information_class_t { - file_directory_information = 1, - file_full_directory_information, - file_both_directory_information, - file_basic_information, - file_standard_information, - file_internal_information, - file_ea_information, - file_access_information, - file_name_information, - file_rename_information, - file_link_information, - file_names_information, - file_disposition_information, - file_position_information, - file_full_ea_information, - file_mode_information, - file_alignment_information, - file_all_information, - file_allocation_information, - file_end_of_file_information, - file_alternate_name_information, - file_stream_information, - file_pipe_information, - file_pipe_local_information, - file_pipe_remote_information, - file_mailslot_query_information, - file_mailslot_set_information, - file_compression_information, - file_copy_on_write_information, - file_completion_information, - file_move_cluster_information, - file_quota_information, - file_reparse_point_information, - file_network_open_information, - file_object_id_information, - file_tracking_information, - file_ole_directory_information, - file_content_index_information, - file_inherit_content_index_information, - file_ole_information, - file_maximum_information -}; - -enum semaphore_information_class { - semaphore_basic_information = 0 -}; - -struct file_name_information_t { - unsigned long FileNameLength; - wchar_t FileName[1]; -}; - -struct file_rename_information_t { - int Replace; - void *RootDir; - unsigned long FileNameLength; - wchar_t FileName[1]; -}; - -struct unicode_string_t { - unsigned short Length; - unsigned short MaximumLength; - wchar_t *Buffer; -}; - -struct object_attributes_t { - unsigned long Length; - void * RootDirectory; - unicode_string_t *ObjectName; - unsigned long Attributes; - void *SecurityDescriptor; - void *SecurityQualityOfService; -}; - -struct io_status_block_t { - union { - long Status; - void *Pointer; - }; - - unsigned long *Information; -}; - -union system_timeofday_information -{ - struct data_t - { - __int64 liKeBootTime; - __int64 liKeSystemTime; - __int64 liExpTimeZoneBias; - unsigned long uCurrentTimeZoneId; - unsigned long dwReserved; - } data; - unsigned char Reserved1[SystemTimeOfDayInfoLength]; -}; - -struct interprocess_by_handle_file_information -{ - unsigned long dwFileAttributes; - interprocess_filetime ftCreationTime; - interprocess_filetime ftLastAccessTime; - interprocess_filetime ftLastWriteTime; - unsigned long dwVolumeSerialNumber; - unsigned long nFileSizeHigh; - unsigned long nFileSizeLow; - unsigned long nNumberOfLinks; - unsigned long nFileIndexHigh; - unsigned long nFileIndexLow; -}; - -enum system_information_class { - system_basic_information = 0, - system_performance_information = 2, - system_time_of_day_information = 3, - system_process_information = 5, - system_processor_performance_information = 8, - system_interrupt_information = 23, - system_exception_information = 33, - system_registry_quota_information = 37, - system_lookaside_information = 45 -}; - -enum object_information_class -{ - object_basic_information, - object_name_information, - object_type_information, - object_all_information, - object_data_information -}; - -enum section_information_class -{ - section_basic_information, - section_image_information -}; - -struct object_name_information_t -{ - unicode_string_t Name; - wchar_t NameBuffer[1]; -}; - -struct interprocess_eventlogrecord -{ - unsigned long Length; // Length of full record - unsigned long Reserved; // Used by the service - unsigned long RecordNumber; // Absolute record number - unsigned long TimeGenerated; // Seconds since 1-1-1970 - unsigned long TimeWritten; // Seconds since 1-1-1970 - unsigned long EventID; - unsigned short EventType; - unsigned short NumStrings; - unsigned short EventCategory; - unsigned short ReservedFlags; // For use with paired events (auditing) - unsigned long ClosingRecordNumber; // For use with paired events (auditing) - unsigned long StringOffset; // Offset from beginning of record - unsigned long UserSidLength; - unsigned long UserSidOffset; - unsigned long DataLength; - unsigned long DataOffset; // Offset from beginning of record - // - // Then follow: - // - // wchar_t SourceName[] - // wchar_t Computername[] - // SID UserSid - // wchar_t Strings[] - // BYTE Data[] - // CHAR Pad[] - // unsigned long Length; - // -}; - -//Kernel32.dll - -//Some windows API declarations -extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId(); -extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId(); -extern "C" __declspec(dllimport) int __stdcall GetProcessTimes - ( void *hProcess, interprocess_filetime* lpCreationTime - , interprocess_filetime *lpExitTime,interprocess_filetime *lpKernelTime - , interprocess_filetime *lpUserTime ); -extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long); -extern "C" __declspec(dllimport) unsigned long __stdcall GetTickCount(void); -extern "C" __declspec(dllimport) int __stdcall SwitchToThread(); -extern "C" __declspec(dllimport) unsigned long __stdcall GetLastError(); -extern "C" __declspec(dllimport) void __stdcall SetLastError(unsigned long); -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) long __stdcall GetFileType(void *hFile); -extern "C" __declspec(dllimport) void *__stdcall FindFirstFileA(const char *lpFileName, win32_find_data_t *lpFindFileData); -extern "C" __declspec(dllimport) int __stdcall FindNextFileA(void *hFindFile, win32_find_data_t *lpFindFileData); -extern "C" __declspec(dllimport) int __stdcall FindClose(void *hFindFile); -//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) void __stdcall GetSystemInfo (struct system_info *); -extern "C" __declspec(dllimport) int __stdcall FlushViewOfFile (void *, std::size_t); -extern "C" __declspec(dllimport) int __stdcall VirtualUnlock (void *, std::size_t); -extern "C" __declspec(dllimport) int __stdcall VirtualProtect (void *, std::size_t, unsigned long, unsigned long *); -extern "C" __declspec(dllimport) int __stdcall FlushFileBuffers (void *); -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) unsigned long __stdcall GetFileAttributesA(const char *); -extern "C" __declspec(dllimport) int __stdcall CreateDirectoryA(const char *, interprocess_security_attributes*); -extern "C" __declspec(dllimport) int __stdcall RemoveDirectoryA(const char *lpPathName); -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 ReadFile(void *hnd, void *buffer, unsigned long bytes_to_read, unsigned long *bytes_read, 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); -extern "C" __declspec(dllimport) void *__stdcall LoadLibraryA(const char *); -extern "C" __declspec(dllimport) int __stdcall FreeLibrary(void *); -extern "C" __declspec(dllimport) void *__stdcall GetProcAddress(void *, const char*); -extern "C" __declspec(dllimport) void *__stdcall GetModuleHandleA(const char*); -extern "C" __declspec(dllimport) void *__stdcall GetFileInformationByHandle(void *, interprocess_by_handle_file_information*); - -//Advapi32.dll -extern "C" __declspec(dllimport) long __stdcall RegOpenKeyExA(void *, const char *, unsigned long, unsigned long, void **); -extern "C" __declspec(dllimport) long __stdcall RegQueryValueExA(void *, const char *, unsigned long*, unsigned long*, unsigned char *, unsigned long*); -extern "C" __declspec(dllimport) long __stdcall RegCloseKey(void *); - -//Ole32.dll -extern "C" __declspec(dllimport) long __stdcall CoInitializeEx(void *pvReserved, unsigned long dwCoInit); -extern "C" __declspec(dllimport) long __stdcall CoInitializeSecurity( - void* pSecDesc, - long cAuthSvc, - void * asAuthSvc, - void *pReserved1, - unsigned long dwAuthnLevel, - unsigned long dwImpLevel, - void *pAuthList, - unsigned long dwCapabilities, - void *pReserved3 ); - - extern "C" __declspec(dllimport) long __stdcall CoSetProxyBlanket( - IUnknown_BIPC *pProxy, - unsigned long dwAuthnSvc, - unsigned long dwAuthzSvc, - wchar_t *pServerPrincName, - unsigned long dwAuthnLevel, - unsigned long dwImpLevel, - void *pAuthInfo, - unsigned long dwCapabilities); -extern "C" __declspec(dllimport) long __stdcall CoCreateInstance(const GUID_BIPC & rclsid, IUnknown_BIPC *pUnkOuter, - unsigned long dwClsContext, const GUID_BIPC & riid, void** ppv); -extern "C" __declspec(dllimport) void __stdcall CoUninitialize(void); - -//OleAut32.dll -extern "C" __declspec(dllimport) long __stdcall VariantClear(wchar_variant * pvarg); - -//Shell32.dll -extern "C" __declspec(dllimport) int __stdcall SHGetSpecialFolderPathA - (void* hwnd, const char *pszPath, int csidl, int fCreate); - -extern "C" __declspec(dllimport) int __stdcall SHGetFolderPathA(void *hwnd, int csidl, void *hToken, unsigned long dwFlags, const char *pszPath); - -//EventLog access functions - static const unsigned long eventlog_sequential_read = 0x0001; static const unsigned long eventlog_backwards_read = 0x0008; -extern "C" __declspec(dllimport) void* __stdcall OpenEventLogA - (const char* lpUNCServerName, const char* lpSourceName); - -extern "C" __declspec(dllimport) int __stdcall CloseEventLog(void *hEventLog); - -extern "C" __declspec(dllimport) int __stdcall ReadEventLogA - (void *hEventLog, - unsigned long dwReadFlags, - unsigned long dwRecordOffset, - void *lpBuffer, - unsigned long nNumberOfBytesToRead, - unsigned long *pnBytesRead, - unsigned long *pnMinNumberOfBytesNeeded - ); - - -//ntdll.dll -typedef long (__stdcall *NtDeleteFile_t)(object_attributes_t *ObjectAttributes); -typedef long (__stdcall *NtSetInformationFile_t)(void *FileHandle, io_status_block_t *IoStatusBlock, void *FileInformation, unsigned long Length, int FileInformationClass ); -typedef long (__stdcall *NtOpenFile)(void **FileHandle, unsigned long DesiredAccess, object_attributes_t *ObjectAttributes - , io_status_block_t *IoStatusBlock, unsigned long ShareAccess, unsigned long Length, unsigned long OpenOptions); -typedef long (__stdcall *NtQuerySystemInformation_t)(int, void*, unsigned long, unsigned long *); -typedef long (__stdcall *NtQueryObject_t)(void*, object_information_class, void *, unsigned long, unsigned long *); -typedef long (__stdcall *NtQuerySemaphore_t)(void*, unsigned int info_class, interprocess_semaphore_basic_information *pinfo, unsigned int info_size, unsigned int *ret_len); -typedef long (__stdcall *NtQuerySection_t)(void*, section_information_class, interprocess_section_basic_information *pinfo, unsigned long info_size, unsigned long *ret_len); -typedef long (__stdcall *NtQueryInformationFile_t)(void *,io_status_block_t *,void *, long, int); -typedef long (__stdcall *NtOpenFile_t)(void*,unsigned long ,object_attributes_t*,io_status_block_t*,unsigned long,unsigned long); -typedef long (__stdcall *NtClose_t) (void*); -typedef long (__stdcall *NtQueryTimerResolution_t) (unsigned long* LowestResolution, unsigned long* HighestResolution, unsigned long* CurrentResolution); -typedef long (__stdcall *NtSetTimerResolution_t) (unsigned long RequestedResolution, int Set, unsigned long* ActualResolution); - -//kernel32.dll -typedef int (__stdcall *QueryPerformanceCounter_t) (__int64 *lpPerformanceCount); -typedef int (__stdcall *QueryPerformanceFrequency_t)(__int64 *lpFrequency); - } //namespace winapi { } //namespace interprocess { } //namespace boost { + namespace boost { namespace interprocess { namespace winapi { @@ -1085,10 +1222,10 @@ inline unsigned long get_current_process_id() inline unsigned int close_handle(void* handle) { return CloseHandle(handle); } -inline void * find_first_file(const char *lpFileName, win32_find_data_t *lpFindFileData) +inline void * find_first_file(const char *lpFileName, win32_find_data *lpFindFileData) { return FindFirstFileA(lpFileName, lpFindFileData); } -inline bool find_next_file(void *hFindFile, win32_find_data_t *lpFindFileData) +inline bool find_next_file(void *hFindFile, win32_find_data *lpFindFileData) { return FindNextFileA(hFindFile, lpFindFileData) != 0; } inline bool find_close(void *handle) @@ -1211,7 +1348,7 @@ inline bool flush_file_buffers(void *handle) { return 0 != FlushFileBuffers(handle); } inline bool get_file_size(void *handle, __int64 &size) -{ return 0 != GetFileSizeEx(handle, &size); } +{ return 0 != GetFileSizeEx(handle, (large_integer*)&size); } inline bool create_directory(const char *name) { @@ -1229,7 +1366,10 @@ inline int set_end_of_file(void *handle) { return 0 != SetEndOfFile(handle); } 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); } +{ + large_integer d; d.QuadPart = distance; + return 0 != SetFilePointerEx(handle, d, (large_integer*)new_file_pointer, move_method); +} 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); } @@ -1262,28 +1402,28 @@ inline long interlocked_exchange(long volatile* addend, long value) { return BOOST_INTERLOCKED_EXCHANGE(const_cast(addend), value); } //Forward functions -inline void *load_library(const char *name) +inline hmodule load_library(const char *name) { return LoadLibraryA(name); } -inline bool free_library(void *module) +inline bool free_library(hmodule module) { return 0 != FreeLibrary(module); } -inline void *get_proc_address(void *module, const char *name) +inline void *get_proc_address(hmodule module, const char *name) { return GetProcAddress(module, name); } inline void *get_current_process() { return GetCurrentProcess(); } -inline void *get_module_handle(const char *name) +inline hmodule get_module_handle(const char *name) { return GetModuleHandleA(name); } -inline long reg_open_key_ex(void *hKey, const char *lpSubKey, unsigned long ulOptions, unsigned long samDesired, void **phkResult) +inline long reg_open_key_ex(hkey hKey, const char *lpSubKey, unsigned long ulOptions, unsigned long samDesired, hkey *phkResult) { return RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, phkResult); } -inline long reg_query_value_ex(void *hKey, const char *lpValueName, unsigned long*lpReserved, unsigned long*lpType, unsigned char *lpData, unsigned long*lpcbData) +inline long reg_query_value_ex(hkey hKey, const char *lpValueName, unsigned long*lpReserved, unsigned long*lpType, unsigned char *lpData, unsigned long*lpcbData) { return RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); } -inline long reg_close_key(void *hKey) +inline long reg_close_key(hkey hKey) { return RegCloseKey(hKey); } inline void initialize_object_attributes @@ -1331,18 +1471,18 @@ struct function_address_holder static void *FunctionAddresses[NumFunction]; static unsigned int FunctionModules[NumFunction]; static volatile long FunctionStates[NumFunction]; - static void *ModuleAddresses[NumModule]; + static hmodule ModuleAddresses[NumModule]; static volatile long ModuleStates[NumModule]; - static void *get_module_from_id(unsigned int id) + static hmodule get_module_from_id(unsigned int id) { BOOST_ASSERT(id < (unsigned int)NumModule); - void *addr = get_module_handle(ModuleNames[id]); + hmodule addr = get_module_handle(ModuleNames[id]); BOOST_ASSERT(addr); return addr; } - static void *get_module(const unsigned int id) + static hmodule get_module(const unsigned int id) { BOOST_ASSERT(id < (unsigned int)NumModule); for(unsigned i = 0; ModuleStates[id] < 2; ++i){ @@ -1437,7 +1577,7 @@ template volatile long function_address_holder::FunctionStates[function_address_holder::NumFunction]; template -void *function_address_holder::ModuleAddresses[function_address_holder::NumModule]; +hmodule function_address_holder::ModuleAddresses[function_address_holder::NumModule]; template volatile long function_address_holder::ModuleStates[function_address_holder::NumModule]; @@ -1450,8 +1590,8 @@ struct dll_func //Complex winapi based functions... struct library_unloader { - void *lib_; - library_unloader(void *module) : lib_(module){} + hmodule lib_; + library_unloader(hmodule module) : lib_(module){} ~library_unloader(){ free_library(lib_); } }; @@ -1490,7 +1630,8 @@ inline bool get_boot_and_system_time(unsigned char (&bootsystemstamp) [BootAndSy return true; } -inline bool get_boot_time_str(char *bootstamp_str, std::size_t &s) //will write BootstampLength chars +inline bool get_boot_time_str(char *bootstamp_str, std::size_t &s) + //will write BootstampLength chars { if(s < (BootstampLength*2)) return false; @@ -1526,7 +1667,8 @@ inline void buffer_to_wide_str(const void *buf, std::size_t length, wchar_t *str } } -inline bool get_boot_and_system_time_wstr(wchar_t *bootsystemstamp, std::size_t &s) //will write BootAndSystemstampLength chars +inline bool get_boot_and_system_time_wstr(wchar_t *bootsystemstamp, std::size_t &s) + //will write BootAndSystemstampLength chars { if(s < (BootAndSystemstampLength*2)) return false; @@ -1578,7 +1720,8 @@ class nt_query_mem_deleter static const std::size_t rename_offset = offsetof(ntquery_mem_t, ren.info.FileName) - offsetof(ntquery_mem_t, name.Name.Buffer); // Timestamp process id atomic count - static const std::size_t rename_suffix = (SystemTimeOfDayInfoLength + sizeof(unsigned long) + sizeof(boost::uint32_t))*2; + static const std::size_t rename_suffix = + (SystemTimeOfDayInfoLength + sizeof(unsigned long) + sizeof(boost::uint32_t))*2; public: nt_query_mem_deleter(std::size_t object_name_information_size) @@ -1604,7 +1747,9 @@ class nt_query_mem_deleter { return static_cast(static_cast(m_buf)); } unsigned long object_name_information_size() const - { return static_cast(m_size - rename_offset - SystemTimeOfDayInfoLength*2); } + { + return static_cast(m_size - rename_offset - SystemTimeOfDayInfoLength*2); + } std::size_t file_rename_information_size() const { return static_cast(m_size); } @@ -1761,16 +1906,16 @@ inline bool unlink_file(const char *filename) struct reg_closer { - void *key_; - reg_closer(void *key) : key_(key){} + hkey key_; + reg_closer(hkey key) : key_(key){} ~reg_closer(){ reg_close_key(key_); } }; inline void get_shared_documents_folder(std::string &s) { - #if 0 //Original registry search code + #if 1 //Original registry search code s.clear(); - void *key; + hkey key; if (reg_open_key_ex( hkey_local_machine , "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders" , 0 @@ -1795,13 +1940,13 @@ inline void get_shared_documents_folder(std::string &s) } } #else //registry alternative: SHGetSpecialFolderPathA - const int IG_CSIDL_COMMON_APPDATA = 0x0023; // All Users\Application Data - const int IG_CSIDL_FLAG_CREATE = 0x8000; // new for Win2K, or this in to force creation of folder - const int IG_SHGFP_TYPE_CURRENT = 0; // current value for user, verify it exists + const int BIPC_CSIDL_COMMON_APPDATA = 0x0023; // All Users\Application Data + const int BIPC_CSIDL_FLAG_CREATE = 0x8000; // new for Win2K, or this in to force creation of folder + const int BIPC_SHGFP_TYPE_CURRENT = 0; // current value for user, verify it exists s.clear(); char szPath[max_path]; - if(0 == SHGetFolderPathA(0, IG_CSIDL_COMMON_APPDATA | IG_CSIDL_FLAG_CREATE, 0, IG_SHGFP_TYPE_CURRENT, szPath)){ + if(0 == SHGetFolderPathA(0, BIPC_CSIDL_COMMON_APPDATA | BIPC_CSIDL_FLAG_CREATE, 0, BIPC_SHGFP_TYPE_CURRENT, szPath)){ s = szPath; } @@ -1811,7 +1956,7 @@ inline void get_shared_documents_folder(std::string &s) inline void get_registry_value(const char *folder, const char *value_key, std::vector &s) { s.clear(); - void *key; + hkey key; if (reg_open_key_ex( hkey_local_machine , folder , 0 @@ -1904,7 +2049,7 @@ inline bool get_wmi_class_attribute( std::wstring& strValue, const wchar_t *wmi_ IWbemServices_BIPC *pWbemServices = 0; if( 0 != pIWbemLocator->ConnectServer( - bstrNamespace, // Namespace + (bstr)bstrNamespace, // Namespace 0, // Userid 0, // PW 0, // Locale @@ -1942,8 +2087,8 @@ inline bool get_wmi_class_attribute( std::wstring& strValue, const wchar_t *wmi_ IEnumWbemClassObject_BIPC * pEnumObject = 0; if ( 0 != pWbemServices->ExecQuery( - L"WQL", - strValue.c_str(), + (bstr)L"WQL", + (bstr)strValue.c_str(), //WBEM_FLAG_RETURN_IMMEDIATELY_BIPC, WBEM_FLAG_RETURN_WHEN_COMPLETE_BIPC | WBEM_FLAG_FORWARD_ONLY_BIPC, 0, @@ -1966,9 +2111,9 @@ inline bool get_wmi_class_attribute( std::wstring& strValue, const wchar_t *wmi_ while( 0 == pEnumObject->Next( WBEM_INFINITE_BIPC, uCount, &pClassObject, &uReturned ) ) { com_releaser IWbemClassObject_releaser(pClassObject); - if ( 0 == pClassObject->Get( L"LastBootUpTime", 0, &vwchar, 0, 0 ) ){ + if ( 0 == pClassObject->Get( (bstr)L"LastBootUpTime", 0, &vwchar, 0, 0 ) ){ bRet = true; - strValue = vwchar.value.pbstrVal; + strValue = (wchar_t*)vwchar.bstrVal; VariantClear(&vwchar ); break; } diff --git a/include/boost/interprocess/windows_shared_memory.hpp b/include/boost/interprocess/windows_shared_memory.hpp index f2195ac..73c1d01 100644 --- a/include/boost/interprocess/windows_shared_memory.hpp +++ b/include/boost/interprocess/windows_shared_memory.hpp @@ -60,13 +60,13 @@ class windows_shared_memory //!Represents an empty windows_shared_memory. windows_shared_memory(); - //!Creates a new native shared memory with name "name" and mode "mode", + //!Creates a new native shared memory with name "name" and at least size "size", //!with the access mode "mode". //!If the file previously exists, throws an error. windows_shared_memory(create_only_t, const char *name, mode_t mode, std::size_t size, const permissions& perm = permissions()) { this->priv_open_or_create(ipcdetail::DoCreate, name, mode, size, perm); } - //!Tries to create a shared memory object with name "name" and mode "mode", with the + //!Tries to create a shared memory object with name "name" and at least size "size", with the //!access mode "mode". If the file previously exists, it tries to open it with mode "mode". //!Otherwise throws an error. windows_shared_memory(open_or_create_t, const char *name, mode_t mode, std::size_t size, const permissions& perm = permissions()) @@ -112,6 +112,10 @@ class windows_shared_memory //!Returns the mapping handle. Never throws mapping_handle_t get_mapping_handle() const; + //!Returns the size of the windows shared memory. It will be a 4K rounded + //!size of the "size" passed in the constructor. + offset_t get_size() const; + /// @cond private: @@ -152,6 +156,12 @@ inline mapping_handle_t windows_shared_memory::get_mapping_handle() const inline mode_t windows_shared_memory::get_mode() const { return m_mode; } +inline offset_t windows_shared_memory::get_size() const +{ + offset_t size; //This shall never fail + return (m_handle && winapi::get_file_mapping_size(m_handle, size)) ? size : 0; +} + inline bool windows_shared_memory::priv_open_or_create (ipcdetail::create_enum_t type, const char *filename, mode_t mode, std::size_t size, const permissions& perm) { diff --git a/proj/vc7ide/Interprocess.sln b/proj/vc7ide/Interprocess.sln index 0773ac8..758d3d5 100644 --- a/proj/vc7ide/Interprocess.sln +++ b/proj/vc7ide/Interprocess.sln @@ -479,6 +479,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "named_condition_any_test", ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "boost_use_windows_h", "boost_use_windows_h.vcproj", "{518CE8C3-6512-FA75-46EF-B917A3A116D1}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -967,6 +971,10 @@ Global {58CC2563-6092-48FE-FAF7-BA046A792658}.Debug.Build.0 = Debug|Win32 {58CC2563-6092-48FE-FAF7-BA046A792658}.Release.ActiveCfg = Release|Win32 {58CC2563-6092-48FE-FAF7-BA046A792658}.Release.Build.0 = Release|Win32 + {518CE8C3-6512-FA75-46EF-B917A3A116D1}.Debug.ActiveCfg = Debug|Win32 + {518CE8C3-6512-FA75-46EF-B917A3A116D1}.Debug.Build.0 = Debug|Win32 + {518CE8C3-6512-FA75-46EF-B917A3A116D1}.Release.ActiveCfg = Release|Win32 + {518CE8C3-6512-FA75-46EF-B917A3A116D1}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/proj/vc7ide/boost_use_windows_h.vcproj b/proj/vc7ide/boost_use_windows_h.vcproj new file mode 100644 index 0000000..2e2391f --- /dev/null +++ b/proj/vc7ide/boost_use_windows_h.vcproj @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/boost_use_windows_h.cpp b/test/boost_use_windows_h.cpp new file mode 100644 index 0000000..2fb1a61 --- /dev/null +++ b/test/boost_use_windows_h.cpp @@ -0,0 +1,38 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// +#define _WIN32_WINNT 0x0501 +#define BOOST_USE_WINDOWS_H + +#include +#include + +#ifdef BOOST_INTERPROCESS_WINDOWS + +#include + +using namespace boost::interprocess; + +int main () +{ + windows_shared_memory dummy; + static_cast(dummy); + return 0; +} + +#else + +int main() +{ + return 0; +} + +#endif + +#include diff --git a/test/windows_shared_memory_mapping_test.cpp b/test/windows_shared_memory_mapping_test.cpp index 9442d80..1143849 100644 --- a/test/windows_shared_memory_mapping_test.cpp +++ b/test/windows_shared_memory_mapping_test.cpp @@ -32,7 +32,8 @@ int main () //Create a file mapping windows_shared_memory mapping (create_only, names[i_name], read_write, FileSize); - + if(mapping.get_size() < FileSize) + return 1; { //Create two mapped regions, one half of the file each