C++ Service中OpenFileMapping"拒绝访问"错误

权限问题,客户端没有访问服务中共享内存(FileMapping)的权限。
参考http://blog.csdn.net/sky04/article/details/5933239。

PSECURITY_DESCRIPTOR pSec = (PSECURITY_DESCRIPTOR)LocalAlloc(LMEM_FIXED, SECURITY_DESCRIPTOR_MIN_LENGTH);
if(!pSec)
{
    return GetLastError();
}
if(!InitializeSecurityDescriptor(pSec, SECURITY_DESCRIPTOR_REVISION))
{
    LocalFree(pSec);
    return GetLastError();
}
if(!SetSecurityDescriptorDacl(pSec, TRUE, NULL, TRUE))
{
    LocalFree(pSec);
    return GetLastError();
}
SECURITY_ATTRIBUTES attr;
attr.bInheritHandle = FALSE;
attr.lpSecurityDescriptor = pSec;
attr.nLength = sizeof(SECURITY_ATTRIBUTES);
HANDLE hFile = CreateFileMapping(INVALID_HANDLE_VALUE, &attr, PAGE_READWRITE, 0, 1024, "test");
LocalFree(pSec);

你可能感兴趣的:(C++ Service中OpenFileMapping"拒绝访问"错误)