Last active
February 15, 2024 23:14
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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