Help with Macintosh programming

macintosh programming, mac programming, mac os programming, mac os x programming, mac programming language, mac programing

Help with GetIndString

I’m working on a program, and I need a function that acts exactly like
Get1IndString(), except that only searches files 1-deep (ala Get1Resource,
Get1IndResource, etc.).  Do I really have to write my own version of this
function, or is there some easier way of doing what I need to do?  

Basically, I’ve got a bunch of STR#’s in my application, and I’m opening
and reading from documents that may (or may not) have STR#’s in them as
well.  The STR#’s will have varying ID numbers (non-sequential).  So, I
may have STR#128, 130, and 200 in my application, and have an STR #300 in
my document.  So right now I’m calling Count1Resources(‘STR#’) after
opening my document file, which tells me how many STR# resources are in it
(the Count1Resources() function only looks at the specified resources
types in the resource file currently specified as being "used" most
recently).  But I cannot then do GetIndString, because I do not know the
ID # of the string itself.  Is there a way to get the resource ID#’s for
the first STR# resource, then the second, etc.?

Thanks!

- Walter Korman             "It is now pitch black.  You are likely
  wkor…@ucsd.edu           to be eaten by a grue."         – Zork

.
posted by admin in Uncategorized and have Comments (2)

2 Responses to “Help with GetIndString”

  1. admin says:

    wkor…@ucsd.edu (Walter Korman) wrote:

    ) …
    ) But I cannot then do GetIndString, because I do not know the
    ) ID # of the string itself.  Is there a way to get the resource
    ) ID#’s for the first STR# resource, then the second, etc.?

    Try the following.  It won’t be a speed deamon, but at least it
    won’t hit the disk.

    #define kBadRsrcID (-32767)

    // Return the resource ID of the resource of the given type at the
    // given index.  Return kBadRsrcID if it can’t be found.

    short Get1IndRsrcID( OSType rType, short index )
    {
        short   rsrcID;
        Boolean oldResLoad;
        Handle  rsrcH;
        Str255  rName;

        oldResLoad = LMGetResLoad();
        SetResLoad( false );

        rsrcH = Get1IndResource( rType, index );
        if( rsrcH != NULL )
            GetResInfo( rsrcH, &rsrcID, &rType, rName );
        else
            rsrcID = kBadRsrcID;
        SetResLoad( oldResLoad );
        return rsrcID;

    }

    Note: I wrote this on the fly, so there may be bugs…

    Cheers,
    Rob
    _______________________________________________________________________
    Robert S. Mah        Macintosh Software Development     +1.212.947.6507
    One Step Beyond         and Network Consulting           r…@panix.com

  2. admin says:

    In article <wkorman-1212940309460…@wkorman.extern.ucsd.edu>,
    Walter Korman <wkor…@ucsd.edu> wrote:

    |But I cannot then do GetIndString, because I do not know the
    |ID # of the string itself.  Is there a way to get the resource ID#’s for
    |the first STR# resource, then the second, etc.?

    You can use Get1IndResource to access resources by index in the current
    resource file.  So Get1IndResource (‘STR#’, 5) returns a handle to the
    5th resource of type STR#, using only the current resource file.

    Another option might be to write a wrapper to GetIndString something like
    (off the top of my head, so undoubtedly fraught with errors):

    Get1IndString (theString, strListID, index)
    {
        SetResLoad (0);
        Handle      h = GetResource (‘STR#’, strListID);
        SetResLoad (1);

        if (HomeResFile (h) != CurResFile ())
            fail somehow;

        GetIndString (theString, strListID, index);

    }

    Of course just writing your own Get1IndString would be fairly simple,
    and probably wouldn’t add any more code than the above method.

    Brian

    Brian L. Matthews                                       b…@halcyon.com
      You can’t have a syntax error with a hammer.