Article View: comp.sys.amiga.tech
Article #5856Re: Accessing NewMenu UserData
From: Peter Cherna
Date: Mon, 15 Oct 1990 15:43
Date: Mon, 15 Oct 1990 15:43
38 lines
1905 bytes
1905 bytes
In article <9194@milton.u.washington.edu> dlarson@blake.u.washington.edu (Dale Larson) writes:
>
>I want to use the UserData field of the NewMenu struct to hold a pointer
>to a function to be called when a particular item is selected. I am a little
>dense and/or the documentation on GTMENUITEM_GETUSERDATA() is a little scant.
>Likely a little of both. Could someone please provide an example of what the
>fuction call would look like?
Let's say your function returned a BOOL and took a UWORD as its parameter:
BOOL (*fcn)(UWORD);
fcn = GTMENUITEM_USERDATA( ItemAddress( menu, selection ) );
return = (*fcn)(code);
(Note that its' GTMENUITEM_USERDATA, not GTMENUITEM_GETUSERDATA.)
>(*GTMENUITEM_GETUSERDATA(ItemAddress(Menu, (long)selection)))();
>just doesn't seem to cut it with my compiler, and since cdecl doesn't
>understand the cast in the GTMENUITEM_GETUSERDATA macro, I don't either.
Your problem is that GTMENUITEM_USERDATA() returns an APTR (which
is really a void* ). You'd have to cast that into a pointer-to-function
before you can invoke it as a function.
>
>Thanks for any help!
>
>--
>-Dale Larson (dlarson@blake.u.washington.edu)
Peter
--
Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
{uunet|rutgers}!cbmvax!peter peter@cbmvax.cbm.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"Television is a medium because it is neither rare nor well-done."
Technical Details
Message-ID:
<15157@cbmvax.commodore.com>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!sun-barr!rutgers!cbmvax!peterReferences:
<9194@milton.u.washington.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!sun-barr!rutgers!cbmvax!peter From: peter@cbmvax.commodore.com (Peter Cherna) Newsgroups: comp.sys.amiga.tech Subject: Re: Accessing NewMenu UserData Message-ID: <15157@cbmvax.commodore.com> Date: 15 Oct 90 15:43:33 GMT References: <9194@milton.u.washington.edu> Reply-To: peter@cbmvax.commodore.com (Peter Cherna) Organization: Commodore, West Chester, PA Lines: 38