Solved

Error codes for socket

Posted on 1998-07-07
7
265 Views
Last Modified: 2013-11-19
I used GetLastError on a socket and it gives me a number.  Now I want to match the numbers with
the msgs like WSANETDOWN and WSANOTCONN, but it says they're undeclared.  How do I figure out
which errors correspond to the numbers that GetLastError is Spitting out?
0
Comment
Question by:zorker
7 Comments
 

Expert Comment

by:platiumstar
ID: 1318830
see MSDN article  "Turning API Errors into Basic Errors".
basically, you use either ApiRaiseIf() or the function here:

Function ApiError(ByVal e As Long) As String

    Dim s As String, c As Long

    s = String(256, 0)

    c = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or _

                      FORMAT_MESSAGE_IGNORE_INSERTS, _

                      pNull, e, 0&, s, Len(s), ByVal pNull)

    If c Then ApiError = Left$(s, c)

End Function

good luck.

0
 

Author Comment

by:zorker
ID: 1318831
Where can I find the MSDN article?
0
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1318832
void ShowSystemError(const TCHAR* lpszTitle, const TCHAR* lpszText, DWORD dwErrorCode)
{
    const TCHAR* lpszWinError;
    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
        NULL,
        dwErrorCode,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpszWinError,
        1,
        NULL
      );

    CString s,s2;
    if(lpszText)
    {
        s = lpszText;
        s += "\n";
    }

    s2 = lpszWinError;
    LocalFree((HLOCAL)lpszWinError);

    s2.TrimLeft();
    s2.TrimRight();

    s += s2;

    if(AfxGetMainWnd())
    {
        MessageBox(AfxGetMainWnd()->m_hWnd, s, lpszTitle,
            MB_OK | MB_ICONERROR | MB_DEFBUTTON1 | MB_APPLMODAL | MB_TOPMOST);
    }
    else
    {
        MessageBox(NULL, s, lpszTitle,
            MB_OK | MB_ICONERROR | MB_DEFBUTTON1 | MB_APPLMODAL | MB_TOPMOST);
    }
}


Use the function this way:

void ShowSystemError("Title Of Dialog", "An error occured:",GetLastError());
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:zorker
ID: 1318833
I tried it, but it gave me a dialog box that said:
"An Error occurred." without the name of the app or the error type.

This is the code I used to call ShowSysErr:
ShowSystemError("IPSerial", "An Error Occurred: ", GSocket.GetLastError());
Where GSocket is the CAsyncSocket.
0
 

Author Comment

by:zorker
ID: 1318834
I tried it, but it gave me a dialog box that said:
"An Error occurred." without the name of the app or the error type.

This is the code I used to call ShowSysErr:
ShowSystemError("IPSerial", "An Error Occurred: ", GSocket.GetLastError());
Where GSocket is the CAsyncSocket.
0
 

Author Comment

by:zorker
ID: 1318835
I tried it, but it gave me a dialog box that said:
"An Error occurred." without the name of the app or the error type.

This is the code I used to call ShowSysErr:
ShowSystemError("IPSerial", "An Error Occurred: ", GSocket.GetLastError());
Where GSocket is the CAsyncSocket.
0
 

Accepted Solution

by:
zingo earned 50 total points
ID: 1318836
To answer your original question, the error definitions for sockets are to be found in winsock.h . I usually write my own PrintSocketError() routine to print an intelligent comment for each error. Unfortunately, I don't have the routine here.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now