How do I get error info after using WinGetLastError()?

One should only use WinGetLastError() after a bad return value, ERRORID is not always zeroed after a successful call to PM API.

ShowError Function:

/*
 * ShowError -- for debugging: outputs (via printf) the last error;
 *    to use this, redirect the output of this program to a file and
 *    check the results in that file.
 *    Updated to display the error text in a MESSAGE BOX; ID_MSGBOX must be
 *    defined.
 */
 void ShowError(void)
 {
    PERRINFO p;
    char *cp;
    extern HAB hab;   /* kinda kludgy, should be a parameter */

    printf("ShowError: ");
    if((p = WinGetErrorInfo(hab)) == NULL)
       printf("NO ERROR\n");
    else
    {
       printf("idError = %#X\n", p->idError);
       cp = (char *)((ULONG)p + *(ULONG *)((ULONG)p + p->offaoffszMsg));
       printf("\"%s\"\n", cp);
       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, (PSZ)cp, (PSZ)"Show Error",
                     ID_MSGBOX, MB_OK | MB_ICONEXCLAMATION);
       WinFreeErrorInfo(p);
    }
 }

Credit: Justin V Frank


[Back: How do I use the 16-bit EPM toolkit?]
[Next: Do you have code to save/restore the clipboard?]