C++ServiceのOpen FileMapping「アクセス拒否」エラー

1331 ワード

権限の問題は、クライアントがサービスにアクセスしてメモリを共有する権限がありません。参照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);