传递DWORD*到映射文件

Passing DWORD* to mapped file

本文关键字:映射 文件 DWORD 传递      更新时间:2023-10-16

这个例子http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx传递了一个TCHAR,但是我如何使它传递一个DWORD呢?我在下面尝试过,但我无法将参数1从'DWORD *'转换为'const wchar_t *'。

DWORD* pid=new DWORD[20];
    HANDLE hMapFile;
    DWORD pBuf;
    TCHAR szName[]=TEXT("Global\mapFile");
    //il creez
    hMapFile = CreateFileMapping(
        INVALID_HANDLE_VALUE,    // use paging file
        NULL,                    // default security 
        PAGE_READWRITE,          // read/write access
        0,                       // maximum object size (high-order DWORD) 
        256,                      // maximum object size (low-order DWORD)  
        szName);                 // name of mapping object
    if (hMapFile == NULL)
    {
        _tprintf(TEXT("Could not create file mapping object (%d).n"),
            GetLastError()); 
        return 1;
    }
    pBuf = (DWORD) MapViewOfFile(hMapFile,   // handle to map object
        FILE_MAP_ALL_ACCESS, // read/write permission
        0,                   
        0,                   
        256);     
    if (pBuf == NULL) 
    {
        _tprintf(TEXT("Could not map view of file (%d).n"),
            GetLastError());
        CloseHandle(hMapFile);
        return 1;
    }
CopyMemory((LPVOID)pBuf, pid, (_tcslen(pid) * sizeof(TCHAR)));

Mapviewoffile返回LPVOID。下一种工作方式:

DWORD*  pBuf = (DWORD*) MapViewOfFile(hMapFile,   // handle to map object
    FILE_MAP_ALL_ACCESS, // read/write permission
    0,                   
    0,                   
    256);     
if (pBuf == NULL) 
{
    _tprintf(TEXT("Could not map view of file (%d).n"),
        GetLastError());
    CloseHandle(hMapFile);
    return 1;
}
CopyMemory((LPVOID)pBuf, pid, (20* sizeof(DWORD)));