This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Win32 error


On Thu, 15 Mar 2001, Corinna Vinschen wrote:

> I am sure, at least for NT/W2K. Sorry, there's no such command in
> 9x/ME.
> 
> However, the error message is:
> 
> $ net helpmsg 127
> 
> The specified procedure could not be found.
> 

For general windows 32, you can use the attached trivial piece of code
that will give you the error message when given the error code.

  
  $ gcc -o win32-error win32-error.c
  $ ./win32-error 127
  ./win32-error.exe (Error 127): The specified procedure could not be found.

Regards,
Mumit

/*
 * win32-errmsg: Translate win32 error codes to text messages.
 *
 * Usage: win32-errmsg [error-code [error-code ...]]
 *
 */

#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

void
format_error (char *msg, int msglen, int errnum)
{
  if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM
                     | FORMAT_MESSAGE_IGNORE_INSERTS,
                     NULL,
                     errnum,
                     MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
                     (LPTSTR) msg,
                     msglen,
                     NULL))
    {
      msg [strlen (msg) - 2] = '\0';
    }
  else
    {
      sprintf (msg, "Win32 error %d", errnum);
    }
}


int 
main (int argc, char *argv[])
{
  int i;
  for (i = 1; i < argc; i++)
    {
      int errnum = atoi (argv[i]);
      char msg[256];

      sprintf (msg, "%s (Error %d): ", argv[0], errnum);
      format_error (msg + strlen (msg), sizeof (msg) - strlen (msg), errnum);
      puts (msg);
    }
  return 0;
}

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]