好不容易找到的,折磨我好几天,症状为键盘记录dll创建一个共享内存,打开IE8,失效。补上下面代码就OK了。
//vista和win7下面,要用相对低权限创建:
SECURITY_ATTRIBUTES secAttr;
char secDesc[ SECURITY_DESCRIPTOR_MIN_LENGTH ];
secAttr.nLength = sizeof(secAttr);
secAttr.bInheritHandle = FALSE;
secAttr.lpSecurityDescriptor = &secDesc;
InitializeSecurityDescriptor(secAttr.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(secAttr.lpSecurityDescriptor, TRUE, 0, FALSE);
//这里最好判断一下win的版本号,vista以上的系统才应用下面的代码 :
PSECURITY_DESCRIPTOR pSD;
ConvertStringSecurityDescriptorToSecurityDescriptor(
_T("S:(ML;;NW;;;LW)"), // 这个描述符意味着 "低权限"
SDDL_REVISION_1,
&pSD,
NULL);
PACL pSacl = NULL;
BOOL fSaclPresent = FALSE;
BOOL fSaclDefaulted = FALSE;
GetSecurityDescriptorSacl(
pSD,
&fSaclPresent,
&pSacl,
&fSaclDefaulted);
SetSecurityDescriptorSacl(secAttr.lpSecurityDescriptor, TRUE, pSacl, FALSE);
hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
&secAttr, // default security
PAGE_READWRITE, // read/write access
0, // max. object size
BUF_SIZE, // buffer size
szName); // name of mapping object