following codes from https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPMultipleUsers/Concepts/UserSwitchNotifications.html#//apple_ref/doc/uid/20002210-CJBJDAGF
demonstrates how to be aware of user switch event . But i can't use this code for user switch purpose ,and it doesn't work for me. How to use this code to be notified when user switch occurs?
pascal OSStatus switchEventsHandler (EventHandlerCallRef nextHandler,
EventRef switchEvent,
void* userData)
{
if (GetEventKind(switchEvent)== kEventSystemUserSessionDeactivated)
{
// Perform deactivation tasks here.
}
else
{
// Perform activation tasks here.
}
return noErr;
}
void SwitchEventsRegister()
{
EventTypeSpec switchEventTypes[2];
EventHandlerUPP switchEventHandler;
switchEventTypes[0].eventClass = kEventClassSystem;
switchEventTypes[0].eventKind = kEventSystemUserSessionDeactivated;
switchEventTypes[1].eventClass = kEventClassSystem;
switchEventTypes[1].eventKind = kEventSystemUserSessionActivated;
switchEventHandler = NewEventHandlerUPP(switchEventsHandler);
InstallApplicationEventHandler(switchEventHandler, 2,
switchEventTypes, NULL, NULL);