I am working on .net platform and using C++ to write my application. When I am using the following code to create a global shared memory to store some value in windows XP, it is perfectly working but on using it in Windows 7, it is giving error so I applied security attributes also but still it is giving permission specific error.
//Global declaration
TCHAR szName[]=TEXT("Global\\MyObject");
bool CreateDACL(SECURITY_ATTRIBUTES *sa)
{
wchar_t *sdd = L"D:P(A;OICI;GA;;;SY)(A;OICI;GA;;;BA)(A;OICI;GRGW;;;IU)";
return ConvertStringSecurityDescriptorToSecurityDescriptor((LPCSTR)sdd, SDDL_REVISION_1, &sa->lpSecurityDescriptor, NULL) == TRUE;
}
void CreateShareMemory()
{
HANDLE hMapFile =NULL; // Create handle
// Check if already created
hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
szName); // name of mapping object
// If not created, then create
if(hMapFile == NULL)
{
SECURITY_ATTRIBUTES sa;
CreateDACL(&sa);
hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
&sa, // default security
PAGE_READWRITE|SEC_COMMIT, // read/write access
0, // max. object size
256, // buffer size
szName); // name of mapping object
int i=GetLastError(); // Here it is giving error no 5
}
}