Logging Data

This is a discussion on Logging Data within the C++ Programming forums, part of the General Programming Boards category; Originally posted by anonytmouse Code: #include <windows.h> #include <stdio.h> void DisplayError( LPSTR msg, DWORD err ) { char msgbuf[4096]; sprintf(msgbuf,"%s\nWindows ...

  1. #16
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by anonytmouse
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    void DisplayError( LPSTR msg, DWORD err )
    {
    	char msgbuf[4096];
    
    	sprintf(msgbuf,"%s\nWindows Error %d: ",msg, err );
    
    	FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
    		MAKELANGID( LANG_NEUTRAL, SUBLANG_DEFAULT),
    		msgbuf + lstrlen(msgbuf), sizeof( msgbuf ) - lstrlen(msgbuf), NULL );
    
    	MessageBox(NULL,msgbuf,"Error",MB_ICONERROR);
    }
    This didn't help me at all, I want to display the error as a string, not a #. Thanks though.

    Hunter, I'll see what I can do with it.

  2. #17
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    This didn't help me at all, I want to display the error as a string, not a #. Thanks though.
    The supplied code will display the error message associated with the supplied error number.

    Code:
    bRet = ReadFile(...);
    if (!bRet) {
         DisplayError("Some Context.", GetLastError() );
    }
    Sample output:
    Some Context.
    Windows Error 38: Reached the end of the file.

    Alternatively you can write a thousand plus switch case with the error messages and numbers found here:
    http://msdn.microsoft.com/library/en...rror_codes.asp

    Please consider actually trying the code.

    Have Fun!

  3. #18
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by anonytmouse
    The supplied code will display the error message associated with the supplied error number.

    Code:
    bRet = ReadFile(...);
    if (!bRet) {
         DisplayError("Some Context.", GetLastError() );
    }
    Sample output:
    Some Context.
    Windows Error 38: Reached the end of the file.

    Alternatively you can write a thousand plus switch case with the error messages and numbers found here:
    http://msdn.microsoft.com/library/en...rror_codes.asp

    Please consider actually trying the code.

    Have Fun!
    I did try the code....I got something like that working anyhow, thanks though.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 09:55 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 11:36 AM
  4. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 08:11 PM
  5. File Database & Data Structure :: C++
    By kuphryn in forum C++ Programming
    Replies: 0
    Last Post: 02-24-2002, 11:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21