I am having another problem related to string resources. The demo
below show the problem. In the demo below a resource file is opened or
created and then 3 strings are saved in a STR# resource. This seems to
work fine. I can see the strings if I open the resource file in Rezilla.
Subsequently when I check the number strings in the resource I get
wrong information. The first word of the STR# resource should give the
number of strings in the resource. But when I run the demo I get 768
instead of 3.
When I look at the string resource in Rezilla I see that the first
byte of the string resource contains the 3, not the second as I would
expect. It seems to me that the length word for string resources
should always be stored in big endin format. Otherwise there are two
different string resource formats, one for intel and one for ppc, and
no way to tell them apart.
Even if string resources have two different formats I don't understand
why the demo below fails since the string resource is created and
checked on the same system.
Any help would be appreciated.
-Joe Lertola
include "Util_Files.incl"
_tempStrList = 4002
begin globals
dim as int gExternalResId
end globals
'~'5
local fn openOrMakeRezFile
dim as int err
DIM AS fsSpec targetSpec
dim as str255 appName$, msg$
appName$ = "MyTestRezFile.rsrc"'name of resource file to be stored in
same folder as the program. "::::TheExtResFile"'four colons to get the
file out of the bundle {8/14/06}
err = fn FSMakeFSSpec( system( _aplVRefNum ), system( _aplParID ),
appName$, @targetSpec )
print
long if Usr FSFileExists(targetSpec)
'file exists
gExternalResId = fn FSpOpenResFile( targetSpec, _fsRdWrPerm )
print "Opening external gradient resource file: " + targetSpec.name
xelse
'no file
Open "O", #1, @targetSpec'create a new resource file in the same
folder as the app
close #1
FSpCreateResFile( targetSpec, _"GeoZ", _"GRAD", _smSystemScript )
gExternalResId = fn FSpOpenResFile( targetSpec, _fsRdWrPerm )
LONG IF gExternalResId <> 0
print "New resource file created: "+targetSpec.name
xelse
print "Could not open new external resource file."
end if
end if
end fn
'~'5
LOCAL FN apndElement(theID,theTxt$)
'Add an element to the end of a STR# resource.
'~'
DIM resHndl&,err,OSErr
resHndl& = FN GETRESOURCE(_"STR#",theID)
err = _noErr
LONG IF resHndl&
call HNOPURGE(resHndl&)
DEF APNDSTR(theTxt$,resHndl&)
call changedresource(resHndl&)
err = FN RESERROR
END IF
END FN = err
'~'5
local fn makeStringResource
dim as int err
dim as handle rH
rH=FN GETRESOURCE(_"STR#",_tempStrList)'delete the temp list
LONG IF rH
CALL RemoveResource(rH)
rH = _nil
print "CALL RemoveResource executed"
xelse
print "did not find _tempStrList"
end if
/*
You are not initialising the proto-STR# Handle correctly.
Replace:
rH = FN NEWHANDLE (2)
by:
rH = FN NewHandleClear( 2 )
Robert P.
*/
rH = FN NEWHANDLEclear (2)
long if rH
DEF APNDSTR("JoAnna",rH)
rH = USR ReplaceResource(rH, _"STR#", _tempStrList, "tempList",
gExternalResId )
print "1 string resource added to resource file"
err = FN apndElement(_tempStrList,"Isaac")
long if err
print "Error could not add a string to the string resource"
xelse
print "2 string resources added to resource file"
end if
err = FN apndElement(_tempStrList,"Cleo")
long if err
print "Error could not add a string to the string resource"
xelse
print "3 string resources added to resource file"
end if
CALL UPDATERESFILE (gExternalResId)
xelse
print "Could not make a handle"
end if
end fn
'~'5
local fn checkResFile
dim as handle resHndl&
dim as int theCount
resHndl& = FN GETRESOURCE(_"STR#",_tempStrList)
LONG IF resHndl&
theCount = {[resHndl&]}
print "The number of strings reported is " + str$(theCount)
print "The high byte of the number of strings reported is " + str$
(peek([resHndl&]))
print "The low byte of the number of strings reported is " + str$
(peek([resHndl&] + 1))
XELSE
print "Could not make a handle for the resource in fn checkResFile"
END IF
end fn
'~'5
window 1
fn openOrMakeRezFile
fn makeStringResource
fn checkResFile
'~'5
do
HandleEvents
until gFBQuit