This example demonstrates how to create a message with inserts from a system message file. It creates a file named "SAMPLE.TXT" with the following 3 lines in it: compact.

It then generates a message file by issuing the following command at an OS/2 command prompt:

MKMSGF SAMPLE.TXT SAMPLE.MSG

#define INCL_DOSMISC    /* Miscellaneous values */#define INCL_DOSERRORS  /* DOS Error values */
#include <os2.h>
#include <stdio.h>
#include <string.h>

int main(VOID) {
UCHAR   *IvTable[2] = {0};                   /* Table of variables to insert */
UCHAR   szOutMsg[80]= "";                    /* Message buffer */
ULONG   ulMsgLen    = 0;                     /* Length of returned message */
APIRET  rc          = 0;                     /* Return code */

IvTable[0] = "Automation Failure";
IvTable[1] = "69B";

    /* Create error message with inserts from system message file SAMPLE.MSG */

rc = DosGetMessage(IvTable,          /* Message insert pointer array */
                   2,                /* Number of inserts */
                   szOutMsg,         /* Output message */
                   sizeof(szOutMsg), /* Length of output message area */
                   1000L,            /* Number of message requested */
                   "SAMPLE.MSG",     /* Message file (created by MKMSGF) */
                   &ulMsgLen);       /* Length of resulting output message */
if (rc != NO_ERROR) {
   printf("DosGetMessage error: return code = %u\n", rc);
   return 1;
}

printf("%s\n", szOutMsg);

return NO_ERROR;
}


[Back] [Next]