[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] hwo to write resource ?



hi,

material: macperl5.13,macOS7.5.3,LC630 20Mo +virtual (40Mo of total ram)
I m trying to do simple things such as
ResToText (reading a resource in a resource fork an returning it):
IT WORKS!!!( script at the end of the msg)
but the TextToRes (writing the resource ) NOT!
I gave you the source, if somebody could explain me why ???

($temp is the Handle, $a the text)
I ve try to do 
....
$temp = Get1Resource($rtype,$id);
if (!defined $temp) { print "OOOOOOOOPPS : error!!\n";}
$temp->set(0,length($a),$a);
UpdateResFile $RFD;
....

AND

....
$temp = Get1Resource($rtype,$id);
if (!defined $temp) { print "OOOOOOOOPPS : error!!\n";}
RemoveResource($temp);
$temp = new Handle($a);
AddResource($rtype,$id,"");
UpdateResFile $RFD;
.....

many, many thanks in advance



sub ResToText
#
# given a file,rtype,id return the text resource
#
{
	local($file,$rtype,$id)=@_;
	local ($RFD,$temp,$a);
	if ( defined OpenResFile($file) )
	{
		print "res of $file opened \n";
		$RFD = CurResFile();
		$temp = Get1Resource($rtype,$id);
  if (!defined $temp) { die "OOOOOOOOPPS : error!!\n";}
		$a = $temp->get(0,$temp->size);
		print "longueur len".length($a)."\n";
		print "longueur size".$temp->size."\n";
		CloseResFile $RFD;
		print "res of $file close \n";
		}
else 
	{
		print "no res in file $file \n";
	}
return $a;
}


-- 

Laurent BARDI Ingenieur Systemes & Reseaux 
Centre National de la Recherche Scientifique
INSTITUT  de PHARMACOLOGIE et de BIOLOGIE STRUCTURALE
Tel : 05-61-17-59-47             http://www.ipbs.fr/scipol/
Fax : 05-61-17-59-94             lolo@ipbs.fr
CNRS-IPBS 205 Route de Narbonne 31400 TOULOUSE FRANCE 

///////////////////////////////////////////////////////////////////////////
/ There is worse than to have not succeded :                              /
/ Not to have  tried !                                                    /
///////////////////////////////////////////////////////////////////////////

If it stinks, it's chemistry. If it moves, it's biology.
If it does not work, It's computer science.

Linux the choice of a GNU generation