I have written two NT services which communicate via a shared memory
block. Now a user process (display process) should attach to the same
shared memory, though this does not work due to a "access denied"
error on OpenFileMapping.
I'm creating the shared memory in the service with:
CreateFileMapping((HANDLE) 0xffffffff, NULL, PAGE_READWRITE, 0,
size, name);
this works perfectly between services and between user processes
but when a user process wants to "OpenFileMapping" such a shared memory
allocated by a service, I get an "access denied" error.
I suppose I need to setup the SECURITY_ATTRIBUTES (second parameter
of CreateFileMapping) in a special way to allow the user process
to attach to this shared memory.
So my question: Can anyone tell me how to setup an SECURITY_ATTRIBUTES
structure to get this going?
Thanks a lot -- Tom
--
--------------------------------------------------------------------------
T o m L e i t n e r Dept. of Communications
Graz University of Technology,
e-mail : t...@finwds01.tu-graz.ac.at Inffeldgasse 12
Phone : +43-316-873-7455 A-8010 Graz / Austria / Europe
Fax : +43-316-463-697
Home page : http://wiis.tu-graz.ac.at/people/tom.html
PGP public key on : ftp://wiis.tu-graz.ac.at/pgp-keys/tom.asc or send
mail with subject "get Thomas Leitner" to pgp-pub...@keys.pgp.net
--------------------------------------------------------------------------
I solve this problem by creating the
FILE MAPPING by the User-Process. Now
the Win32-Service can open this
FileMapping and the User-Process can
communicate with the Service.
I have got the same Problem with Mutex.
If a Win32-Service call "CreateMutex" a
normal process cannot open this Mutex.
The Error is also "Access denied".
Sigmar
/* MUTEX stuff */
int mutex_init(HANDLE *mutex,const TCHAR *attr)
{
SECURITY_ATTRIBUTES SecurityAttributes;
SECURITY_DESCRIPTOR SecurityDescriptor;
// set security to NULL so everyone can read/write our memory file
InitializeSecurityDescriptor(&SecurityDescriptor,
SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&SecurityDescriptor, // address of security
descriptor
TRUE, // flag for presence of discretionary ACL
NULL, // discretionary ACL of NULL gives everyone access
FALSE // flag for default discretionary ACL
);
SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor = (LPVOID)&SecurityDescriptor;
SecurityAttributes.bInheritHandle = FALSE;
*mutex = CreateMutex(&SecurityAttributes, // no security attributes
FALSE, // initially not owned
attr); // name of mutex
if (*mutex == NULL)
{
LPSTR lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
// Display the string.
printf("Can't create mutex: %u\n", GetLastError());
// Free the buffer.
LocalFree( lpMsgBuf );
return 1;
}
return 0;
}
int mutex_open(HANDLE *mutex, const TCHAR *attr)
{
*mutex = OpenMutex(MUTEX_ALL_ACCESS, // full access
FALSE, // no inherit
attr); // name of mutex
if (*mutex == NULL)
return 1;
return 0;
}