Solved

'icns' resouce type

Posted on 1998-10-30
7
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sumNumber challenge 16 148
Path of Workbook 3 88
Work with App store 7 122
listing all the respondents to a twitter feed - Java 5 49
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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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