On 11/30/05 9:16 PM, Ben Zhu didst favor us with:
> Larry,
>
> I never write Carbon event code before.
An understanding of Carbon Events is essential to writing a modern Carbon
application. There is documentation on Apple's web site. Go this page and
search for "Carbon Event":
http://developer.apple.com/documentation/Carbon/index-title.html
And read CarbonEvents.h in its entirety. Unlike Windows headers, there is a
lot of good information in some of the Mac headers and this is one of the
best to read.
> So I have the following
> two questions:
>
> 1. After running the function installEventHandler that installs the
> MonitorHandler function and loop to wait a volume event comes up, but it
> never. Which kind of events I need to register in the following kEvent
> array?
Uh, the one you're handling in your handler?
> installEventHandler(void)
> {
> EventTypeSpec kEvent[] =
> {
> {kEventClassVolume, kEventCommondProcess}
This code won't compile because "kEventCommondProcess" isn't the correct
spelling. It's kEventCommandProcess.
In any case, if you read CarbonEvents.h you saw that there are only two
events in kEventClassVolume, and neither of them is kEventCommondProcess. So
why are you registering for a "kEventCommondProcess" event when you want to
handle a kEventVolumeMounted event? It should be:
EventTypeSpec kEvent[] =
{
{kEventClassVolume, kEventVolumeMounted}
};
or
EventTypeSpec kEvent[] =
{
{kEventClassVolume, kEventVolumeMounted},
{kEventClassVolume, kEventVolumeUnmounted}
};
if you want to handle both.
> };
>
> InstallEvenHandler(GetEventMonitorTarget(),MonitorHandler,
> GetEvenTypeCount(kEvents)), kEvents,
> 0, &myHandler);
Why are you posting code that won't compile (GetEvenTypeCount is
misspelled)?
>
> RunApplicationEventLoop();
>
> }
> static OSStatus
> MonitorHandler( EventHandlerCallRef inCaller,
> EventRef inEvent, void* inRefcon )
> {
> FSVolumeRefNum volRefNum;
>
> // get the event class
> switch ( GetEventClass( inEvent ) )
> {
> case kEventClassVolume:
>
> switch ( GetEventKind( inEvent ) )
> {
> case kEventVolumeMounted:
> case kEventVolumeUnmounted:
>
> GetEventParameter(
> inEvent,
> typeFSVolumeRefNum,
> kEventParamDirectObject
> NULL,
> sizeof(FSVolumeRefNum),
> NULL,
> &volRefNum);
>
> break;
>
> default:
> break;
> }
> break;
> default:
> break;
> }
> return noErr;
> }
>
>
>
> 2. Using Event method, It seems I still cannot recognize if the mounted
> volume is or not a USB flash mem stick.
No, you can't use the event to determine that. It simply tells you when a
volume has been mounted so you can test it to see if it's one you want.
>
> Is there any way to tell if the device of the mounted volume is or not a
> USB flash mem stick?
Yes, though I've never done it myself. Sounds like something for which you
would want to use IOKit. The CarbonEvent will tell you when a volume is
mounted, and from there you can get a reference to the volume and ultimately
use that with IOKit. It's going to involve a few steps, but it's doable.
Larry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden
This email sent to email@hidden