14#if QT_CONFIG(sharedmemory)
18 DWORD windowsError = GetLastError();
19 if (windowsError == 0)
21 switch (windowsError) {
22 case ERROR_ALREADY_EXISTS:
23 error = QSharedMemory::AlreadyExists;
24 errorString = QSharedMemory::tr(
"%1: already exists").
arg(function);
26 case ERROR_FILE_NOT_FOUND:
27 error = QSharedMemory::NotFound;
28 errorString = QSharedMemory::tr(
"%1: doesn't exist").
arg(function);
30 case ERROR_COMMITMENT_LIMIT:
31 error = QSharedMemory::InvalidSize;
34 case ERROR_NO_SYSTEM_RESOURCES:
35 case ERROR_NOT_ENOUGH_MEMORY:
36 error = QSharedMemory::OutOfResources;
37 errorString = QSharedMemory::tr(
"%1: out of resources").
arg(function);
39 case ERROR_ACCESS_DENIED:
40 error = QSharedMemory::PermissionDenied;
41 errorString = QSharedMemory::tr(
"%1: permission denied").
arg(function);
44 errorString = QSharedMemory::tr(
"%1: unknown error: %2")
46 error = QSharedMemory::UnknownError;
47#if defined QSHAREDMEMORY_DEBUG
53HANDLE QSharedMemoryWin32::handle(QSharedMemoryPrivate *self)
56 const auto function =
"QSharedMemory::handle"_L1;
58 self->setError(QSharedMemory::KeyError,
59 QSharedMemory::tr(
"%1: unable to make key").
arg(function));
62 hand = OpenFileMapping(FILE_MAP_ALL_ACCESS,
false,
63 reinterpret_cast<const wchar_t *
>(
self->nativeKey.nativeKey().
utf16()));
65 self->setWindowsErrorString(function);
72bool QSharedMemoryWin32::cleanHandle(QSharedMemoryPrivate *)
74 if (hand != 0 && !CloseHandle(hand)) {
82bool QSharedMemoryWin32::create(QSharedMemoryPrivate *self,
qsizetype size)
84 const auto function =
"QSharedMemory::create"_L1;
86 self->setError(QSharedMemory::KeyError,
87 QSharedMemory::tr(
"%1: key error").
arg(function));
97 low = DWORD(
size_t(
size) & 0xffffffff);
98 hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, high, low,
99 reinterpret_cast<const wchar_t *
>(
self->nativeKey.nativeKey().
utf16()));
100 self->setWindowsErrorString(function);
103 return self->error != QSharedMemory::AlreadyExists && hand;
106bool QSharedMemoryWin32::attach(QSharedMemoryPrivate *self, QSharedMemory::AccessMode
mode)
109 int permissions = (
mode == QSharedMemory::ReadOnly ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS);
110 self->memory = (
void *)MapViewOfFile(
handle(self), permissions, 0, 0, 0);
112 self->setWindowsErrorString(
"QSharedMemory::attach"_L1);
118 MEMORY_BASIC_INFORMATION
info;
122 self->setError(QSharedMemory::UnknownError,
123 QSharedMemory::tr(
"%1: size query failed")
124 .
arg(
"QSharedMemory::attach: "_L1));
132bool QSharedMemoryWin32::detach(QSharedMemoryPrivate *self)
135 if (!UnmapViewOfFile(
self->memory)) {
136 self->setWindowsErrorString(
"QSharedMemory::detach"_L1);
143 return cleanHandle(self);
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
qsizetype size() const
Returns the number of characters in this string.
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
DBusConnection const char DBusError * error
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
unsigned long long quint64
QFileInfo info(fileName)
[8]