Solved

Mac Programming question

Posted on 1997-06-20
3
201 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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