测试代码_共享内存

Posted DrMess

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了测试代码_共享内存相关的知识,希望对你有一定的参考价值。

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、

 

以上是关于测试代码_共享内存的主要内容,如果未能解决你的问题,请参考以下文章