码迷,mamicode.com
首页 > 其他好文 > 详细

测试代码_共享内存

时间:2018-01-02 11:24:12      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:col   std   value   ret   include   div   pre   vc6   gpo   

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、

 

测试代码_共享内存

标签:col   std   value   ret   include   div   pre   vc6   gpo   

原文地址:https://www.cnblogs.com/DrMess/p/8175626.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!