| 1 | #include "shared/shme.h" |
| 2 | |
| 3 | bool CreateMemFile(SharedFile* file) { |
| 4 | // Get a handle to our file map |
| 5 | const auto MapFile = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, SHMEMSIZE, SHMEMNAME); |
| 6 | if (MapFile == nullptr) { |
| 7 | MessageBoxA(nullptr, "Failed to create file mapping!", "DLL_PROCESS_ATTACH", MB_OK | MB_ICONERROR); |
| 8 | return false; |
| 9 | } |
| 10 | |
| 11 | // Get our shared memory pointer |
| 12 | const auto MemFile = MapViewOfFile(MapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0); |
| 13 | if (MemFile == nullptr) { |
| 14 | MessageBoxA(nullptr, "Failed to map shared memory!", "DLL_PROCESS_ATTACH", MB_OK | MB_ICONERROR); |
| 15 | return false; |
| 16 | } |
| 17 | file->lpMemFile = MemFile; |
| 18 | file->hMapFile = MapFile; |
| 19 | return true; |
| 20 | } |
| 21 | |
| 22 | bool CloseMemFile(SharedFile* file) { |
| 23 | UnmapViewOfFile(file->lpMemFile); |
no outgoing calls
no test coverage detected