[an error occurred while processing this directive]

HP OpenVMS Systems

C++ Programming Language
Content starts here HP C++

HP C++
Class Library Reference Manual


Previous Contents Index


Chapter 5
Messages Package

The Messages package provides a way to retrieve messages stored in a catalog or file that is separate from your program. It consists of a single class, Messages , that retrieves the text of a message.

Processing a message file on an OpenVMS system requires a message set number and a message number. A message set number is an OpenVMS message identification code, including a facility code (bits 16 through 27) and a facility-specific bit (bit 15); all other bits should be 0. A message number is an integer from 1 to 8191. To process the message file, use the OpenVMS Message Utility (see the OpenVMS Message Utility Manual for details) and link the resulting object code into one of the following:

  • Your program
  • A shareable image that your program is linked against
  • A shareable image that is then specified with the set message command

Messages class

Retrieves message text for a message number.

Header File

#include <messages.hxx>

Alternative Header

None.


Declaration


class Messages 
{ 
public: 
   Messages(const char *filename_arg, int set_arg = 0, 
        const char *default_file_location_arg = (const char *)(NULL)); 
   ~Messages(); 
   
   const char *text(int msg_arg, const char *fallback_text_arg, 
         int set_arg = 0); 
};               

Constructors and Destructors

Messages(const char *filename_arg, int set_arg, const char *default_file_location_arg)

Constructs a Messages object. set_arg specifies the message number to set; a value of 0 specifies that the default set be used. filename_arg and default_file_location_arg are ignored.

~Messages()

Deletes a Messages object.

Member Function

const char *text(int msg_arg, const char *fallback_text_arg, int set_arg)

Returns the text of the message specified by the msg_arg argument. The fallback_text_arg argument indicates the text to return if the message cannot be found. The set_arg argument specifies the message set number; a value of 0 causes the system to use the set number provided to the constructor.

Depending on the process defaults, the facility, error severity, and message identification code may be appended to the beginning of the message (for example, %CXXL-W-E_ONEXT , prefixed to Can't delete an object that is on a list. ).


Example

The following is a sample message source file:

.TITLE      MESSAGES_EXAMPLE_MSG    Example messages -- VMS message catalog 
.IDENT      '1.0' 
.FACILITY   EXAMPLE, 1 /PREFIX=EXAMPLE_ 
 
.BASE 0 
.SEVERITY WARNING    ! we just want a 0 in the severity field 
SET <>               ! message set number 
 
.SEVERITY ERROR 
EXAMPLE_ERROR <This is an example error message> 
 
.END 
      

Entering the following OpenVMS Message Utility commands set the appropriate options and compile this file:


$ set message/nofac/nosev/noid 
$ message/lis MESSAGES_EXAMPLE_MSG 
      

The following program retrieves the sample error message:


#include <iostream.hxx> 
#include <messages.hxx> 
 
const char *message_file_name = (const char *)(NULL); 
const char *message_file_location = (const char *)(NULL); 
#pragma __extern_model __save 
#pragma __extern_model __globalvalue 
extern int EXAMPLE_SET; 
#pragma __extern_model __restore 
int message_set_example = EXAMPLE_SET; 
 
Messages m_example (message_file_name, message_set_example, 
    message_file_location); 
 
int main() 
{ 
    cout << 
        "text of example message 1: " << 
        m_example.text(1, "fallback message 1") << 
        "\n"; 
 
    cout << 
        "text of example message 2: " << 
        m_example.text(2, "fallback message 2") << 
        "\n"; 
 
    return 0; 
} 
 
 
 
      

The following compiler command compiles the program:


$ cxx/lis MESSAGES_EXAMPLE 
      

Entering the following link and run sequence retrieves the text of the error message and displays the second fallback message:


$ link MESSAGES_EXAMPLE,MESSAGES_EXAMPLE_MSG 
 
$ run/nodeb messages_example 
text of example message 1: This is an example error message 
text of example message 2: fallback message 2 
      


Previous Next Contents Index