Solved

Error codes for socket

Posted on 1998-07-07
7
268 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 49
ODBC Connection Logging, ADO.NET 6 64
either24  challenge 19 97
changeXy challenge 13 82
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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