我需要一种在一些线程之间共享内存的机制(通常在同一进程中,但有时不是)。
此代码看起来很基础,但在MapViewOfFile
上由于错误5(访问被拒绝)而失败:
HANDLE hSharedMemCreated = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
10000, // maximum object size (low-order DWORD)
"testFileMapping"); // name of mapping object
HANDLE hSharedMemOpened = OpenFileMapping(
PAGE_READWRITE, // read/write access
FALSE,
"testFileMapping"
);
void* location = MapViewOfFile(
hSharedMemOpened, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
10);
MapViewOfFile
成功打开,并获得权限hSharedMemOpened
的句柄FILE_MAP_READ
。MapViewOfFile
成功创建并获得权限hSharedMemCreated
的句柄FILE_MAP_ALL_ACCESS
。MapViewOfFile
失败,打开的句柄hSharedMemOpened
的权限为FILE_MAP_ALL_ACCESS
。答案 0 :(得分:0)
答案在评论中:
/pathtoFile/window/LPA/cavin_l/LPA_formula_24rw39.csv
/pathtoFile/window/LPA/cavin_l/LPA_formula_24rw39.csv
对于PAGE_READWRITE
无效。您可能需要OpenFileMapping()
。