CreateFileMapping和MapViewOfFile

#include <stdio.h>
#include <windows.h>


int main()
{
    //内存申请物理页
    HANDLE hMapFile = CreateFileMapping(HANDLE(-1), NULL, PAGE_READWRITE, 0, 0x1000, "共享映射");
    //和虚拟地址映射
    LPTSTR lpBuff = (LPTSTR)MapViewOfFile(hMapFile, FILE_MAP_WRITE, 0, 0, 0x1000);

    *(PDWORD)lpBuff = 0x12345678;

    getchar();

    printf("%p\n", lpBuff);
    printf("%x\n", *(PDWORD)lpBuff);
    //printf("%d\n", *lpBuff);
    
    //关闭映射
    UnmapViewOfFile(lpBuff);
    //关闭句柄
    CloseHandle(hMapFile);


    system("pause");
    return(0);
}

posted @ 2020-06-13 10:36  温暖了寂寞  阅读(493)  评论(0编辑  收藏  举报