| 114 | } |
| 115 | |
| 116 | HRESULT HGLOBAL_WriteToFile(HGLOBAL hGlobal, const String& filename) |
| 117 | { |
| 118 | unique_handle hFile(CreateFile(filename.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)); |
| 119 | if (hFile.get() == INVALID_HANDLE_VALUE) |
| 120 | return E_FAIL; |
| 121 | char *p = static_cast<char *>(GlobalLock(hGlobal)); |
| 122 | if (p == nullptr) |
| 123 | return E_FAIL; |
| 124 | SIZE_T size = GlobalSize(hGlobal); |
| 125 | while (size > 0) |
| 126 | { |
| 127 | DWORD dwWritten; |
| 128 | if (WriteFile(hFile.get(), p, (size > INT_MAX) ? INT_MAX : static_cast<DWORD>(size), &dwWritten, nullptr) == FALSE) |
| 129 | { |
| 130 | GlobalUnlock(hGlobal); |
| 131 | return E_FAIL; |
| 132 | } |
| 133 | p += dwWritten; |
| 134 | size -= dwWritten; |
| 135 | } |
| 136 | GlobalUnlock(hGlobal); |
| 137 | return S_OK; |
| 138 | } |
| 139 | |
| 140 | HRESULT SetFileWriteTime(const String& filename, const FILETIME& writetime) |
| 141 | { |
no test coverage detected