Solved

'icns' resouce type

Posted on 1998-10-30
7
172 Views
Last Modified: 2013-12-26
How do I create an 'icns' resource and save it to a resource  file? I tried the following but didn't write the resource properly.
      
 fileId = FSpOpenResFile( &mySpec, fsRdWrPerm);
 myErr = GetIconSuite( &myIconSuite, 140,  svAllAvailableData);
 LoadResource(myIconSuite);
 DetachResource(myIconSuite);
 AddResource(myIconSuite, 'icns', -128, "\p");
      ChangedResource(myIconSuite);      
 CloseResFile( fileId );*/

Any inof on how to create an 'icns' resource from and Handle of IconSuite
0
Comment
Question by:dwp090598
  • 4
  • 3
7 Comments
 

Author Comment

by:dwp090598
ID: 1291572
Edited text of question
0
 
LVL 3

Accepted Solution

by:
boonstra earned 100 total points
ID: 1291573
Delete the LoadResource and DetachResource calls.  LoadResource is used to read a purged resource or one that wasn't loaded because SetResLoad was FALSE.  In your case, GetIconSuite has created the resource data in memory, so LoadResource is not needed.

If you check ResError after the DetachResource call in the code you provided, you'll find you get a resNotFound error.  That's because the myIconSuite isn't part of a resource map yet, so it cannot be detached.

I've run the above code (minus LoadResource and DetachResource) on a resource file that contains icon resources, and it correctly creates an 'icns' resource that I've been able to read it back in.

However, I'm not sure why you want to create and save the 'icns' resource.  Isn't it just as easy to recreate it using GetIconSuite when you need it?
0
 

Author Comment

by:dwp090598
ID: 1291574
this answer showed me how to save a resource correctly, but failed to answer what I really needed to know. What I am trying to do is save an handle pointing to an icon suite to an 'icns' resource. 'icns' resource contains an entire IconFamily and is the new resource apple saves icon pixmap data in. Check the "System Resources" file in Syustem 8.5 for an example.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:boonstra
ID: 1291575
Sorry the answer didn't meet your intent.  I'll try to have another look to see if I can answer the real question.
0
 
LVL 3

Expert Comment

by:boonstra
ID: 1291576
On further investigation, the problem is that the handle created in memory by the GetIconSuite command doesn't match what is written in memory as the 'icns' resource.

It appears that the 'icns' resource data would have to be constructed piece by piece.  By disassembling the 'icns' resource, it appears to have the following format:

4 bytes: 'icns'
4 bytes: number of bytes in resource, minus 4

multiple occurrences of the following:
4 bytes: icon resource type (e.g., ics#')
4 bytes: size (N) of icon data that follows, plus 8
N bytes: icon data
.

I was able to create a valid 'icns' resource containing two icon types ('icl4' and 'icl8') with the following code.  You should be able to tailor this to do what you want.

#define kNumRsrcTypes 2
unsigned long rsrcTypes[kNumRsrcTypes] = {
      'icl4','icl8'
};


int main(void)
{
      FSSpec mySpec = {0,0,"\pMyRsrcFile.rsrc"};
      int fileId,i,j;
      Handle rsrcHdl,suiteRsrcHdl;
      OSErr err;
      long rsrcSize;
      
      fileId = FSpOpenResFile(&mySpec,fsRdWrPerm);
      if (fileId<0) DebugStr("\p could not open file");
      
      suiteRsrcHdl = NewHandle(8);
      *(long *)*suiteRsrcHdl = 'icns';
      *(long *)(4 + *suiteRsrcHdl) = 0;
      
      for (j=0; j<kNumRsrcTypes; j++) {
            for (i=128; i<149; i++) {
                  rsrcHdl = GetResource(rsrcTypes[j],128);
                  rsrcSize = GetHandleSize(rsrcHdl);
                  rsrcSize+=8;
                  err = PtrAndHand(&rsrcTypes[j],suiteRsrcHdl,4);
                  err = PtrAndHand(&rsrcSize,suiteRsrcHdl,4);
                  err = HandAndHand(rsrcHdl,suiteRsrcHdl);
                  *(long *)(4 + *suiteRsrcHdl) += 8+GetHandleSize(rsrcHdl);
            }
      }

      AddResource(suiteRsrcHdl,'icns',-128,"\pmyIconSuite");
      if (noErr!=ResError()) DebugStr("\p res err 3");
      ChangedResource(suiteRsrcHdl);
      if (noErr!=ResError()) DebugStr("\p res err 4");
      CloseResFile(fileId);

      return 0;      
}

0
 

Author Comment

by:dwp090598
ID: 1291577
Thanks boonstra, this really helped.
0
 

Author Comment

by:dwp090598
ID: 1291578
Thanks boonstra, this really helped.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Powershell based monitoring system 2 138
Generic progress indicator 6 113
sum13 challenge 24 90
Change to event 1 99
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now