创建文件内存映射:
HANDLE hMySharedMapFile=CreateFileMapping((HANDLE)0xFFFFFFFF),
NULL,PAGE_READWRITE,0,0x1000,"MySharedMem");
其中第一个参数文件句柄设置成0XFFFFFFFF代表什么意思呢?
0XFFFFFFFF在内存中又是什么意思呢?
为什么要把文件句柄设置成0XFFFFFFFF???

解决方案 »

  1.   

    句柄设置成0XFFFFFFFF表示在内存中开辟一块区域。
      

  2.   

    内存映射API函数CreateFileMapping创建一个有名的共享内存:
    HANDLE CreateFileMapping(
    HANDLE hFile,                       // 映射文件的句柄,
                //设为0xFFFFFFFF以创建一个进程间共享的对象
    LPSECURITY_ATTRIBUTES lpFileMappingAttributes,   // 安全属性
    DWORD flProtect,          // 保护方式
    DWORD dwMaximumSizeHigh,    //对象的大小 
    DWORD dwMaximumSizeLow, 
    LPCTSTR lpName           // 必须为映射文件命名
    );
      

  3.   

        要把文件映像到内存,首先必须调用CreateFileMapping()函数,它需要用一个由CreateFile()函数打开并返回的文件句柄,对大多数共享内存应用程序,必须把此句柄设置为0xFFFFFFFF,用来指定系统页面文件。通过使用上面的特殊句柄,可以不调用CreateFile函数,当然在完成时,也不必有一个内存的磁盘文件拷贝。 
      

  4.   

    0XFFFFFFFF是INVALID_HANDLE_VALUE,表示不指定文件,在系统分页文件(pagefile.sys)中分配映射的磁盘空间。
      

  5.   

    If hFile is (HANDLE)0xFFFFFFFF, the calling process must also specify a mapping object size in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. The function creates a file-mapping object of the specified size backed by the operating-system paging file rather than by a named file in the file system. The file-mapping object can be shared through duplication, through inheritance, or by name. 
      

  6.   

    MSDN:
    If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. In this scenario, CreateFileMapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system.INVALID_HANDLE_VALUE就是-1即0xffffffff
      

  7.   

    -1hFile 
    Handle to the file from which to create a mapping object. The file must be opened with an access mode compatible with the protection flags specified by the flProtect parameter. It is recommended, though not required, that files you intend to map be opened for exclusive access. 
    If hFile is (HANDLE)0xFFFFFFFF, the calling process must also specify a mapping object size in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. The function creates a file-mapping object of the specified size backed by the operating-system paging file rather than by a named file in the file system. The file-mapping object can be shared through duplication, through inheritance, or by name. 
      

  8.   

    咨询一下,CreateFileMapping()能映射硬盘吗?整个硬盘或者逻辑分区? 谢谢!!!