Last change
on this file since 8003 was 8003, checked in by bird, 24 years ago |
New kFile* classes; now in sync with os2tools.
|
File size:
1.8 KB
|
Line | |
---|
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 | *******************************************************************************/
|
---|
18 | #include <os2.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <stdio.h>
|
---|
21 |
|
---|
22 | #include <kTypes.h>
|
---|
23 | #include <kError.h>
|
---|
24 |
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Gets the message text for a given error number.
|
---|
28 | * @return Message text. Caller must delete it.
|
---|
29 | */
|
---|
30 | char *kError::getText(int iErrorNo)
|
---|
31 | {
|
---|
32 | char *psz;
|
---|
33 |
|
---|
34 | if (iErrorNo >= 0 && iErrorNo <= 0x10000)
|
---|
35 | {
|
---|
36 | char szErrorMsg[1024];
|
---|
37 | ULONG cbMsg = sizeof(szErrorMsg);
|
---|
38 | APIRET rc;
|
---|
39 |
|
---|
40 | rc = DosGetMessage(NULL, 0, &szErrorMsg[0], cbMsg, iErrorNo, "OSO001.MSG", &cbMsg);
|
---|
41 | if (rc || cbMsg == 0)
|
---|
42 | cbMsg = sprintf(szErrorMsg,
|
---|
43 | "No error message for error %d. (DosGetMessage -> %d)",
|
---|
44 | iErrorNo, rc);
|
---|
45 | psz = new char[cbMsg + 1];
|
---|
46 | strcpy(psz, szErrorMsg);
|
---|
47 | }
|
---|
48 | else
|
---|
49 | { /* User defined message */
|
---|
50 | char szErrorMsg[50];
|
---|
51 | char * psz2;
|
---|
52 |
|
---|
53 | switch (iErrorNo)
|
---|
54 | {
|
---|
55 |
|
---|
56 | default:
|
---|
57 | sprintf(szErrorMsg, "No error message for error %d.", iErrorNo);
|
---|
58 | psz2 = szErrorMsg;
|
---|
59 | }
|
---|
60 | psz = new char[strlen(psz2) + 1];
|
---|
61 | strcpy(psz, psz2);
|
---|
62 | }
|
---|
63 |
|
---|
64 | return psz;
|
---|
65 | }
|
---|
66 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.