IObjectContext::IsCallerInRole, IObjectContext::IsSecurityEnabled Methods Example
#include <mtx.h>
IObjectContext* pObjectContext = NULL;
BSTR stRole = SysAllocString(L"Manager");
VARIANT_BOOL fIsInRole;
HRESULT hr;
hr = GetObjectContext(&pObjectContext);
// Find out if security is enabled.
if (pObjectContext->IsSecurityEnabled()) {
//Then find out if the caller is in the right role.
fIsInRole = pObjectContext->IsCallerInRole
(stRole, &fIsInRole)
SysFreeString(stRole);
if (!fIsInRole) {
// If not, do something appropriate here.
}
}
else {
// If security's not enabled, do something
// appropriate here.
}