Okay, so I'm not going crazy... I am, in fact, going in the direction you suggest. Thanks for the feedback. It's good to know it's not 'just me', making things more difficult than they have to be.
"Robert McKenzie" <[EMAIL PROTECTED]> wrote in message news:82891@palm-dev-forum... > > It depends on where you got the memory that the pointer references. > > If it was originally from a handle, then MemPtrRecoverHandle (or some such > similar function, I am shooting from memory here) will do your business for > you. > > If it was NOT originally from a handle, then you cannot get a handle for it. > > Handles only reference relocatable memory. If you got your pointer from > MemPtrNew or from a stack variable, then that memory is not relocatable and > there is no handle associated with it. > > For your particular problem in this case, you should (1) get a handle (for > an appropriate amount of memory), (2) lock it, (3) copy the contents of your > memory into the newly allocated area, (4) unlock the handle, and (5) give it > to the field. > > A control's label, by the way, almost certainly never came from a handle. > > -bob mckenzie, palmsource pdx > > -----Original Message----- > From: Geoff Thompson [mailto:[EMAIL PROTECTED]] > Sent: Friday, April 05, 2002 9:31 AM > To: Palm Developer Forum > Subject: Handles and Pointers, oh my! > > > I am new to C and to Palm programming. I have the Palm manuals, and an > assortment of Palm Programming books, and an assortment of C books > (including K&R), but I must be looking in all the wrong places when it comes > to basic concepts that everyone else seems to take for granted. Namely, how > to handle handles. > > I know that handles enable the OS to allocate and reallocate memory more > effectively. The handle is a non-moveable chunk holding the address of the > moveable and resizable chunk of memory. But what if I have a pointer to the > memory, as in the case of a char pointer to a label returned from a > CtlGetLabel? How do I get it's handle? > > For example - I want to set the text of a Field from the label of a Control. > I could allocate additional memory and do a StrCopy, but wouldn't it be more > efficent to set the Field handle to the handle of the Control label? > CtlGetLabel gives me a char pointer to the label. How do I (can I) coerce > that into it's handle? If I do this, I assume that even though the Control > subsequently loses scope (the Control is on one form and the Field is on > another), if the handle is being used by the field (or a global), then the > memory holding the string will not be destroyed. > > I know this is basic, but I seem to be missing a piece of the puzzle. I > would appreciate some advice. Is there a good text (preferably for the Palm > environment) that explains the basics of handles, without assuming that one > is already an proficient C programmer? > > Thanks in advance - > > Geoff Thompson > [EMAIL PROTECTED] > > > > -- > For information on using the Palm Developer Forums, or to unsubscribe, > please see http://www.palmos.com/dev/support/forums/ > > -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
