C
Chris B.
If anyone can figure out how to implement the following C++ function in C#
using interop, I'd be very appreciative.
I have not been successful in getting it to work correctly using interop
(without using unsafe code) because of the pointer issues of the structure.
Thanks,
Chris
//------------------------------------------------------------
HANDLE __stdcall CreateAllAccessMutex(BOOL bInitialOwner, const wchar_t
*pszName)
{
HANDLE rc = NULL;
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
// A security descriptor with a NULL DACL must be used because this
function can be initially called
// by an application running as a service which will create the mutex with
a default security
// descriptor that does not allow user-mode applications to open the mutex
by name with CreateMutex.
if (InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) //
initialize the security descriptor
{
if (SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE)) // add a NULL
DACL to the security descriptor
{
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
rc = CreateMutexW(&sa, bInitialOwner, pszName);
}
}
return rc;
}
using interop, I'd be very appreciative.
I have not been successful in getting it to work correctly using interop
(without using unsafe code) because of the pointer issues of the structure.
Thanks,
Chris
//------------------------------------------------------------
HANDLE __stdcall CreateAllAccessMutex(BOOL bInitialOwner, const wchar_t
*pszName)
{
HANDLE rc = NULL;
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
// A security descriptor with a NULL DACL must be used because this
function can be initially called
// by an application running as a service which will create the mutex with
a default security
// descriptor that does not allow user-mode applications to open the mutex
by name with CreateMutex.
if (InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) //
initialize the security descriptor
{
if (SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE)) // add a NULL
DACL to the security descriptor
{
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
rc = CreateMutexW(&sa, bInitialOwner, pszName);
}
}
return rc;
}