[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error codes for socket

Posted on 1998-07-07
7
Medium Priority
?
276 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

873 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