home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!libramac.uwaterloo.ca!iclegrow
- From: Ian LeGrow <iclegrow@sail.uwaterloo.ca>
- Subject: Help creating resources with AddResource
- Message-ID: <C19GDG.8ws@watserv2.uwaterloo.ca>
- X-Xxmessage-Id: <A785762D9D013256@libramac.uwaterloo.ca>
- X-Xxdate: Fri, 22 Jan 93 15:00:13 GMT
- Sender: news@watserv2.uwaterloo.ca
- Organization: University of Waterloo
- X-Useragent: Nuntius v1.1.1d9
- Date: Fri, 22 Jan 1993 15:00:52 GMT
- Lines: 53
-
- I'm trying to write a routine to create a resource (a simple task I'm
- sure). Below is my routine ( it compiles and runs with TC 5.0.3 with the
- #includes.c and MacTraps in the project). I used the DoCopyResource
- example form IM-Files to create my routine but the resource is not
- created. The file is created with a resource fork but when I open the
- file with ResEdit it says that it needs minor repairs and is OK -- but no
- resource. My full routine checks ResError() often but this never returns
- an error. I also call UseResFile(fileRefNum) but this makes no difference.
-
- Do I need to sent the file to disk? Does FSClose not close the resource?
- Am I not Initing a necessary manager?
-
- Thanks in advance... this silly problem has caused me much grief.
-
-
- #include "Script.h"
-
- void main(void)
- {
- Str255 defaultName="\pjunkfile";
- OSErr fileError=0;
- StandardFileReply reply;
- int fileRefNum,volNum;
- short i;
- Str255 tempName="\pname of the resource";
- Handle tempHandle;
-
- /*init stuff*/
- MaxApplZone();
- for (i=1;i<=4;i++) MoreMasters();
- FlushEvents(everyEvent,0);
- InitGraf(&thePort);InitFonts();InitWindows();InitMenus();
- TEInit();InitDialogs(0L);InitCursor();
- /* init*/
-
- StandardPutFile((StringPtr)"\pSave File As:",defaultName,&reply);
- fileError=FSpCreate(&(reply.sfFile),'FMN ','TEXT',smSystemScript);
- FSpCreateResFile(&(reply.sfFile),'FMN ','TEXT',smSystemScript);
- fileRefNum=FSpOpenResFile(&(reply.sfFile),fsRdWrPerm);
- if (fileRefNum>0) {
- PtrToHand("some text",&tempHandle,10);
- AddResource(tempHandle,'TEXT',1000,tempName);
- WriteResource(tempHandle);
- ReleaseResource(tempHandle);
- }
- fileError=GetVRefNum(fileRefNum,&volNum); /* needed ???*/
- fileError=FlushVol(nil,volNum); /* needed ???*/
- fileError=FSClose(fileRefNum);
- }
- ===============================================================
- Ian LeGrow Engineering Computing
- iclegrow@steam.uwaterloo.ca University of Waterloo
- ===============================================================
-