Can't cast to delgate type from void*?

Rick Mann rmann-d-lang at latencyzero.com
Sun Feb 18 18:41:02 PST 2007


I'm trying to use delegates with Mac OS X's carbon events. When you register an event handler with the system, you can pass an arbitrary 4 bytes, which are passed back to you when the event handler is called.

So, I was hoping to use a delegate. In my handler, I try to do this:

extern (C)
OSStatus
EventHandler(EventHandlerCallRef inHandlerCallRef,
                            EventRef inEvent,
                            void* inUserData)
{
    try
    {
        EventHandlerMethod handleEvent = cast (EventHandlerMethod) inUserData;
        .
        .
        .

However, the compiler complains:

DEventHandler.d:119: error: conversion to non-scalar type requested

Why can't I do this?

TIA,
Rick



More information about the Digitalmars-d-learn mailing list