This example loads an error message from ERR.DLL using the resource handle from DosLoadModule and uses the message in a message box.

#define INCL_WINWINDOWMGR       /* Window Manager Functions     */
#define INCL_DOSMODULEMGR       /* Module Manager Functions     */
#define INCL_WINDIALOGS         /* Window Dialog Mgr Functions  */
#include <os2.h>
#define ERRMSG_ID 1

LONG    lLength;        /* length of string                     */
HAB     hab;            /* anchor-block handle                  */
HMODULE hmodDLL;        /* Handle of resource module            */
LONG    lBufferMax = 100;/* Size of buffer                      */
char    pszErrMsg[100]; /* error message                        */
CHAR    LoadError[100]; /* object name buffer for DosLoad       */
ULONG   rc;             /* return code                          */
HWND    hwnd;           /* window handle                        */

/* obtain resource handle */
rc = DosLoadModule(LoadError, sizeof(LoadError), "ERR.DLL",
                   &hmodDLL);

/* load message from resource */
if (rc == 0)
   {
   /* load error message string */
   lLength = WinLoadMessage(hab, hmodDLL, ERRMSG_ID, lBufferMax,
                            pszErrMsg);

   /* display error message box */
   WinMessageBox(HWND_DESKTOP,
       hwnd,                      /* client-window handle   */
       pszErrMsg,                 /* message                */
       "Error message",           /* title of the message   */
       0,                         /* message box id         */
       MB_NOICON | MB_OK);        /* icon and button flags  */
   }


[Back] [Next]