Rev | Line | |
---|
[8003] | 1 | /* $Id: kError.cpp,v 1.1 2002-02-24 02:47:24 bird Exp $
|
---|
| 2 | *
|
---|
| 3 | * Error Wrapper.
|
---|
| 4 | *
|
---|
| 5 | * Copyright (c) 2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
| 6 | *
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | /*******************************************************************************
|
---|
| 10 | * Defined Constants And Macros *
|
---|
| 11 | *******************************************************************************/
|
---|
| 12 | #define INCL_DOSMISC
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | /*******************************************************************************
|
---|
| 16 | * Header Files *
|
---|
| 17 | *******************************************************************************/
|
---|
[21916] | 18 | #if defined (__EMX__) && !defined (USE_OS2_TOOLKIT_HEADERS)
|
---|
| 19 | #define __OS2DEF__
|
---|
| 20 | #endif
|
---|
[8003] | 21 | #include <os2.h>
|
---|
[21916] | 22 |
|
---|
[8003] | 23 | #include <string.h>
|
---|
| 24 | #include <stdio.h>
|
---|
| 25 |
|
---|
| 26 | #include <kTypes.h>
|
---|
| 27 | #include <kError.h>
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * Gets the message text for a given error number.
|
---|
| 32 | * @return Message text. Caller must delete it.
|
---|
| 33 | */
|
---|
| 34 | char *kError::getText(int iErrorNo)
|
---|
| 35 | {
|
---|
| 36 | char *psz;
|
---|
| 37 |
|
---|
| 38 | if (iErrorNo >= 0 && iErrorNo <= 0x10000)
|
---|
| 39 | {
|
---|
| 40 | char szErrorMsg[1024];
|
---|
| 41 | ULONG cbMsg = sizeof(szErrorMsg);
|
---|
| 42 | APIRET rc;
|
---|
| 43 |
|
---|
| 44 | rc = DosGetMessage(NULL, 0, &szErrorMsg[0], cbMsg, iErrorNo, "OSO001.MSG", &cbMsg);
|
---|
| 45 | if (rc || cbMsg == 0)
|
---|
| 46 | cbMsg = sprintf(szErrorMsg,
|
---|
| 47 | "No error message for error %d. (DosGetMessage -> %d)",
|
---|
| 48 | iErrorNo, rc);
|
---|
| 49 | psz = new char[cbMsg + 1];
|
---|
| 50 | strcpy(psz, szErrorMsg);
|
---|
| 51 | }
|
---|
| 52 | else
|
---|
| 53 | { /* User defined message */
|
---|
| 54 | char szErrorMsg[50];
|
---|
| 55 | char * psz2;
|
---|
| 56 |
|
---|
| 57 | switch (iErrorNo)
|
---|
| 58 | {
|
---|
| 59 |
|
---|
| 60 | default:
|
---|
| 61 | sprintf(szErrorMsg, "No error message for error %d.", iErrorNo);
|
---|
| 62 | psz2 = szErrorMsg;
|
---|
| 63 | }
|
---|
| 64 | psz = new char[strlen(psz2) + 1];
|
---|
| 65 | strcpy(psz, psz2);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | return psz;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.