Path: utzoo!attcan!uunet!tank!nic.MR.NET!hal!cwjcc!mailrus!purdue!decwrl!labrea!Portia!Jessica!rick From: rick@Jessica.stanford.edu (Rick Wong) Newsgroups: comp.sys.mac.programmer Subject: Re: GetIndString, where is the reverse? Keywords: GetIndString C ToolBox Message-ID: <4192@Portia.Stanford.EDU> Date: 22 Nov 88 18:58:44 GMT Sender: news@Portia.Stanford.EDU Reply-To: rick@Jessica.stanford.edu (Rick Wong) Distribution: comp.sys.mac.programmer Organization: Stanford University Lines: 35 In article <7010@claris.com> drc@claris.com (Dennis Cohen) writes: >In article <1012@ccnysci.UUCP> cpyang@ccnysci.UUCP (Chao Ping Yang) asks: >> >> [How do you set a string in a string-list resource?] >> > >One way to do this is to call GetResource, DetachResource, RmveResource, >AddResource, and UpdateResFile with the appropriate arguments. > > . . . if you are modifying a string somewhere in the >middle of an STR#, be sure that you move everything after it to correctly >adjust to the new length. > >The safest method is to create a handle to a new item, build your resource >in it, and then add it to the resource file (after removing the one that it >replaces). Be sure to check your error returns at all points through this >process. > An easier method is to use everybody's favorite trap, Munger, which will correctly adjust the location of all following strings. To make sure the Munger call succeeded, you can call GetHandleSize before and after to see if the final handle size is what you expected. In case you need to know the format of a 'STR#' resource, it's a two-byte integer indicating the number of strings, followed by Pascal-format strings. Since the strings can have different lengths, you'll have to do some pointer arithmetic to access a particular string. If you are at a string, you can get to the next one by adding the string's length byte to the current value of your pointer. Be sure to treat the length byte as an unsigned value. >Dennis Cohen Rick Wong Courseware Authoring Tools Project, Stanford University