[comp.sys.mac.programmer] control definition functions without CDEFs?

mcdonald@fornax.UUCP (Ken Mcdonald) (03/12/90)

I'm writing up a bit of source which, eventually, I'd like to distribute.  It
uses custom CDEFs, but one thing I'd like to do is to avoid making users
of the source copy extra CDEFs into their applications--that is, I'd like
to build the custom controls entirely within the source.  The first
problem I've run across (there may be others) is the fact the contrlDefProc
field in a control must be set to a HANDLE to the control definition
procedure--so how do I get a handle to the procedure I'm using, which
is defined in my source?  Second, IM mentions that "You should never
have to access this field directly" (an obvious lie :-) ), so if I insist
on doing things like this, is the system going to burn me?

Any other suggestions in this admittedly unusual endeavour would be
most gratefully received.

Thanks,
Ken McDonald
mcdonald@cs.sfu.ca

asl2@tank.uchicago.edu (Aaron "Fish" Lav) (03/13/90)

In article <423@fornax.UUCP> mcdonald@fornax.UUCP (Ken Mcdonald) writes:
>I'm writing up a bit of source which, eventually, I'd like to distribute.  It
>uses custom CDEFs, but one thing I'd like to do is to avoid making users
>of the source copy extra CDEFs into their applications--that is, I'd like
>to build the custom controls entirely within the source.  The first
>mcdonald@cs.sfu.ca

What you want to do is allocate a six-byte handle, and fill that with a jump
to your procedure's address.  There was a Mactutor example of how to do this
.  If you want I'll try to find it and/or reproduce it.
The handle's contents should be $4EF9 (jmp to 32-bit immed. addr), and then
your procedure address.
That's the way to avoid using fake handles.



					Aaron <><|
asl2@tank.uchicago.edu


Newsgroups: comp.sys.mac.programmer
Subject: Re: control definition functions without CDEFs?
Summary: 
Expires: 
References: <423@fornax.UUCP>
Sender: 
Followup-To: 
Distribution: na
Organization: University of Chicago
Keywords: 

duggie@jessica.Stanford.EDU (Doug Felt) (03/13/90)

In article <8013@tank.uchicago.edu> asl2@tank.uchicago.edu (Aaron "Fish" Lav) writes:
>In article <423@fornax.UUCP> mcdonald@fornax.UUCP (Ken Mcdonald) writes:
>>I'm writing up a bit of source which, eventually, I'd like to distribute.  It
>>uses custom CDEFs, but one thing I'd like to do is to avoid making users
>>of the source copy extra CDEFs into their applications--that is, I'd like
>>to build the custom controls entirely within the source.  The first
>>mcdonald@cs.sfu.ca
>
>What you want to do is allocate a six-byte handle, and fill that with a jump
>to your procedure's address.  There was a Mactutor example of how to do this
>.  If you want I'll try to find it and/or reproduce it.
>The handle's contents should be $4EF9 (jmp to 32-bit immed. addr), and then
>your procedure address.
>That's the way to avoid using fake handles.
>
>					Aaron <><|
>asl2@tank.uchicago.edu

Make sure, by the way, that the procedure is in a segment that will stay
locked while the control is in use.

Perhaps an even better alternative is to dispense with controls
altogether and implement the routines in your own code.  After you've
written the CDEF basically all that's left is TrackControl, so you
might as well write everything yourself.

This not only makes your code cleaner and easier to read, it makes it
easier to provide additional functionality as well (i.e. controls with
floating point values, or multiple independent values, or lots of
parameters).

In my opinion CDEFs aren't worth the hassle unless you need to replace
controls in apps for which you don't have the source.

Doug Felt

stoms@castor.ncgia.ucsb.edu (David Stoms) (03/14/90)

In article <10098@portia.Stanford.EDU> duggie@jessica.Stanford.EDU (Doug Felt) writes:
>In article <8013@tank.uchicago.edu> asl2@tank.uchicago.edu (Aaron "Fish" Lav) writes:
>>In article <423@fornax.UUCP> mcdonald@fornax.UUCP (Ken Mcdonald) writes:
>>>I'm writing up a bit of source which, eventually, I'd like to distribute.  It
>>>uses custom CDEFs, but one thing I'd like to do is to avoid making users
>>>of the source copy extra CDEFs into their applications--that is, I'd like
>>>to build the custom controls entirely within the source.  The first
>>What you want to do is allocate a six-byte handle, and fill that with a jump
>>to your procedure's address.  There was a Mactutor example of how to do this
>Make sure, by the way, that the procedure is in a segment that will stay
>locked while the control is in use.

One more hint-- you should create the control by specifying a real
CDEF resource. To accomplish this, you can use ResEdit or something
to create a six byte CDEF handle on disk. Then do a GetResource and
put in your JMP and address. I don't think your code needs to be in
a locked segment, at least in ThinkC because when you take the address
of a routine I think you get a pointer to a branch to that routine.
At least I think it works like that in ThinkC. Try it, if I'm wrong
correct me but I seem to remember doing it before.

Josh Pritikin