Solved

Mac Programming question

Posted on 1997-06-20
3
182 Views
Last Modified: 2013-12-26
I saw a code sample some time ago that I believe used a STR# resource built into the system to translate sn OSErr error code into an english message. Does anyonw know the resource ID or of any other built-in way to do this. I want to avoid creating a masssive case statement that I have to maintain.
0
Comment
Question by:creality
3 Comments
 
LVL 1

Accepted Solution

by:
Paul B earned 0 total points
ID: 1291517
Yes you can get the error text built in :)
It is tricky though.

There is a file in your development environment called SysErrs.err.
For Codewarior it is in Metrowerks:Metrowerks Codewarior:SysErrs.err.

COPY this file to the same folder as your application.
I am not sure if it works with aliases.

In your project file you need to link with either PPCToolLibs.o for PPC or NuToolLibs.o for 68K

In your source code:
#include <string.h>
#include <stdio.h>

#include <ErrMgr.h>               // Error manager include
#include <Errors.h>

void main(void)
{
    char errorstring[256];        // buffer for error text
    OSErr err;                    // error number
 
    printf("Error test\n");
    pascalStrings = true;         // pascal string for errors
                                  // init the error manager
                                  // first param is path to tool error file
                                  // second is pacth to sys error file
                                  // since the file is in the same folder
                                  // we pass null
                                  // last param to incluyde error number in text
    InitErrMgr(NULL, NULL, true);


      err = notEnoughHardwareErr;   // some error number
                                    // get the error text
      GetSysErrText(err, errorstring);
                                  
      p2cstr((StringPtr)errorstring);// convert pascal to C string
                                     // display error
      printf("%d %s\n", err, errorstring);

}

You may want to look at <ErrMgr.h> for more detail
Good Luck
Paul Baxter
pbaxter@assistivetech.com
0
 

Author Comment

by:creality
ID: 1291518
Paul answer was great. He even provided some source code as a sample, going beyond what I would have expected.



Thanks Paul.
0
 
LVL 3

Expert Comment

by:rickyr
ID: 1291519
Hi.
It is good to see that some are here to help others, rather than for the points.
a perfect example to set for other forums.

All credit to you creality.


0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

19 Experts available now in Live!

Get 1:1 Help Now