测试代码_共享内存

1、VC6

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

void main()
{
    char* pc = "AAA";
    HANDLE hMem = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4, pc);
    if (hMem == NULL)
    {
        printf("CreateFileMapping return NULL");
        return;
    }

    void* pMem = MapViewOfFile(hMem, FILE_MAP_WRITE, 0, 0, 0);
    if (pMem == NULL)
    {
        printf("MapViewOfFile return NULL");
        return;
    }

    UnmapViewOfFile(pMem);
    CloseHandle(hMem);

// ***
    hMem = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4, pc);
    if (hMem == NULL)
    {
        printf("CreateFileMapping return NULL");
        return;
    }

    pMem = MapViewOfFile(hMem, FILE_MAP_WRITE, 0, 0, 0);
    if (pMem == NULL)
    {
        printf("MapViewOfFile return NULL");
        return;
    }

    UnmapViewOfFile(pMem);
    CloseHandle(hMem);

// ***
    hMem = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 4, pc);
    if (hMem == NULL)
    {
        printf("CreateFileMapping return NULL");
        return;
    }

    pMem = MapViewOfFile(hMem, FILE_MAP_WRITE, 0, 0, 0);
    if (pMem == NULL)
    {
        printf("MapViewOfFile return NULL");
        return;
    }

    UnmapViewOfFile(pMem);
    CloseHandle(hMem);
}

 

2、

3、

4、

5、

 

转载于:https://www.cnblogs.com/DrMess/p/8175626.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页