Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Error codes for socket

Posted on 1998-07-07
7
Medium Priority
?
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

618 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