home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 21951 < prev    next >
Encoding:
Text File  |  1993-01-22  |  2.4 KB  |  67 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!libramac.uwaterloo.ca!iclegrow
  3. From: Ian LeGrow <iclegrow@sail.uwaterloo.ca>
  4. Subject: Help creating resources with AddResource
  5. Message-ID: <C19GDG.8ws@watserv2.uwaterloo.ca>
  6. X-Xxmessage-Id: <A785762D9D013256@libramac.uwaterloo.ca>
  7. X-Xxdate: Fri, 22 Jan 93 15:00:13 GMT
  8. Sender: news@watserv2.uwaterloo.ca
  9. Organization: University of Waterloo
  10. X-Useragent: Nuntius v1.1.1d9
  11. Date: Fri, 22 Jan 1993 15:00:52 GMT
  12. Lines: 53
  13.  
  14. I'm trying to write a routine to create a resource (a simple task I'm
  15. sure). Below is my routine ( it compiles and runs with TC 5.0.3 with the
  16. #includes.c and MacTraps in the project). I used the DoCopyResource
  17. example form IM-Files to create my routine but the resource is not
  18. created. The file is created with a resource fork but when I open the
  19. file with ResEdit it says that it needs minor repairs and is OK -- but no
  20. resource. My full routine checks ResError() often but this never returns
  21. an error. I also call UseResFile(fileRefNum) but this makes no difference.
  22.  
  23. Do I need to sent the file to disk? Does FSClose not close the resource?
  24. Am I not Initing a necessary manager?
  25.  
  26. Thanks in advance... this silly problem has caused me much grief.
  27.  
  28.  
  29. #include "Script.h"
  30.  
  31. void main(void)
  32. {
  33.     Str255 defaultName="\pjunkfile";
  34.     OSErr fileError=0;
  35.     StandardFileReply reply;
  36.     int fileRefNum,volNum;
  37.     short i;
  38.     Str255 tempName="\pname of the resource";
  39.     Handle tempHandle;
  40.     
  41.     /*init stuff*/
  42.     MaxApplZone();
  43.     for (i=1;i<=4;i++) MoreMasters();
  44.         FlushEvents(everyEvent,0);
  45.         InitGraf(&thePort);InitFonts();InitWindows();InitMenus();
  46.         TEInit();InitDialogs(0L);InitCursor();
  47.     /* init*/    
  48.     
  49.     StandardPutFile((StringPtr)"\pSave File As:",defaultName,&reply);    
  50.     fileError=FSpCreate(&(reply.sfFile),'FMN ','TEXT',smSystemScript); 
  51.     FSpCreateResFile(&(reply.sfFile),'FMN ','TEXT',smSystemScript);     
  52.     fileRefNum=FSpOpenResFile(&(reply.sfFile),fsRdWrPerm);    
  53.     if (fileRefNum>0)    {
  54.         PtrToHand("some text",&tempHandle,10);
  55.         AddResource(tempHandle,'TEXT',1000,tempName);
  56.         WriteResource(tempHandle);
  57.         ReleaseResource(tempHandle);
  58.         }
  59.     fileError=GetVRefNum(fileRefNum,&volNum); /* needed ???*/
  60.     fileError=FlushVol(nil,volNum);    /* needed ???*/
  61.     fileError=FSClose(fileRefNum); 
  62. }
  63. ===============================================================
  64. Ian LeGrow                        Engineering Computing
  65. iclegrow@steam.uwaterloo.ca            University of Waterloo
  66. ===============================================================
  67.