Skip to content

Instantly share code, notes, and snippets.

@nir9
Last active February 15, 2024 23:14
Show Gist options
  • Save nir9/7f61b01c3299a8a3bcebc2e19151146f to your computer and use it in GitHub Desktop.
Save nir9/7f61b01c3299a8a3bcebc2e19151146f to your computer and use it in GitHub Desktop.
Simple Memory Mapped File Chat in C (Not for production since there is no cleanup and error handling, code is only for fun)
#include <Windows.h>
#include <stdio.h>
int main() {
HANDLE handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, L"ChatSyncFileMap");
LPVOID address = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
HANDLE event = CreateEventW(NULL, FALSE, FALSE, L"ChatSyncEvent");
for (;;) {
WaitForSingleObject(event, INFINITE);
printf("%s", (char*)address);
}
}
#include <Windows.h>
#include <stdio.h>
int main() {
HANDLE handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, L"ChatSyncFileMap");
LPVOID address = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
HANDLE event = CreateEventW(NULL, FALSE, FALSE, L"ChatSyncEvent");
for (;;) {
scanf_s("%255s", (char*)address, 256);
SetEvent(event);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment