Ich muss mmap einer Datei erstellen. Da Windows mmap nicht unterstützt, habe ich die MapViewOfFile() Methode ausprobiert. Aber das scheitert.Windows c: konnte nicht erstellt werden mmap einer Datei
Hier ist mein Code:
char template[1024];
snprintf(template, sizeof(template)/sizeof(char), "%s", "C:\\Users\\Ijas\\Downloads\\ijas.txt");
HANDLE hfile = CreateFile(template, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
if (hfile == INVALID_HANDLE_VALUE)
{
fprintf(stderr, "CreateFile() error 0x%08x \n", GetLastError());
return NULL;
}
HANDLE map_handle = CreateFileMapping(hfile, NULL, PAGE_READWRITE | SEC_RESERVE, 0, 0, 0);
if (map_handle == NULL)
{
fprintf(stderr, "CreateFileMapping() error 0x%08x\n", GetLastError());
CloseHandle(hfile);
return NULL;
}
sp = (char*)MapViewOfFile(map_handle, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 0);
if (sp->buffer == NULL)
{
fprintf(stderr, "MapViewOfFile() error 0x%08x\n", GetLastError());
CloseHandle(hMapFile);
CloseHandle(hfile);
return NULL;
}
Ausgang:
CreateFile() error 0x00000003
Hinweis: Vorlage ist eine vorhandene Datei.
Alles falsch in meinem Code? Bitte hilf mir?
Hat 'ijas.txt' existiert? Sie sollten [GetLastError] (https://msdn.microsoft.com/en-us/library/windows/desktop/ms679360 (v = vs.85) .aspx) aufrufen, um zu sehen, was beim Funktionsaufruf passiert ist. – LPs
Wenn ein Windows-Systemaufruf fehlschlägt, sollten Sie ['GetLastError'] (https://msdn.microsoft.com/en-us/library/windows/desktop/ms679360 (v = vs.85) .aspx) finden Was [der Fehler] (https://msdn.microsoft.com/en-us/library/windows/desktop/ms681381 (v = vs.85) .aspx) ist. –
@JoachimPileborg Ich habe meinen Code und Ausgabe mit GetLastError bearbeitet –