Can't cast to delgate type from void*?

Kirk McDonald kirklin.mcdonald at
Sun Feb 18 20:28:34 PST 2007

Rick Mann wrote:
> 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

Delegates are 8 bytes. They consist of a function pointer and a context 
pointer. I'm not familiar with Carbon's event handling, but I suspect 
that void* is intended to serve the same purpose as a delegate's context 

Kirk McDonald
Pyd: Connecting D and Python

More information about the Digitalmars-d-learn mailing list