Defining a Custom Message Function in C Programs

The C API allows you to supply a custom message handling function which you can use to trap error messages before they are processed by the API. You may want to code a custom message handling function, either to trap particular error conditions, or to ensure uniform processing and display of all user messages throughout your program. If you choose not to supply a custom message function, all message processing is handled by the API default message handler.

To define a custom message function in a program, you must write the function and set the MessageFunc field in the API initialization structure to point to your custom function before calling EssInit().

Coding the Custom Message Handling Function

You can use any name you wish for this function and its arguments, but it must be declared in the following form:

ESS_FUNC_M      CustomMessage (
ESS_PVOID_T     UserContext,     /* user context pointer */
ESS_LONG_T      MessageNumber,   /* Essbase message number */
ESS_USHORT_ T   Level,           /* message level */
ESS_STR_T       LogString,       /* message log string */
ESS_STR_T       MessageString    /* message string */
);

In this code, the fields are defined as follows:

Setting the MessageFunc Field to Point to Your Function

Pointers to the custom message function must be assigned to the MessageFunc field of the initialization structure passed to the EssInit() function (see Initializing the C Main API).

Using a Custom Function to Control Message Processing

The custom message function is called before an Essbase Server returns a message or the Essbase API returns an error. When the function is called, the arguments passed to it contain the message number, message level, log string, and error string for that particular message. For each message, the function can use these argument values to choose whether to process the message, ignore it, or return it to the API for default processing: