|
-
September 20th, 2010, 09:39 PM
#1
Funny thing with WSAStartup()
Hi there!
I have a class named mySocket which is implemented as follow:
////////////////////////////////////////////////////////////////////////////////////////////////////
class mySocket{
private:
WSADATA wsadata;
// ...
public:
////////////////////////////////////////////////////////////////////////////////////////////////////
/// @fn int listen(int nPort)
///
/// @brief Create a socket listening on a specified port
///
/// @param nPort The port number
///
/// @return If success, returns 1. Otherwise, return -1.
////////////////////////////////////////////////////////////////////////////////////////////////////
int listen(int nPort);
// ...
}
int mySocket::listen(int nPort){
int iResult=WSAStartup(MAKEWORD(2,2), &wsadata);
if(iResult!=0){
printf("WSAStartup failsed: %d \n",iResult);
WSACleanup();
return -1;
};
// ...
}
////////////////////////////////////////////////////////////////////////////////////////////////////
In the code above, you can see that wsadata is declared as a property of mySocket. My problem is: WSAStartup() always fails with an error code of 10014 returned. But if I move the declaration of wsadata into the method listen(), there's nothing wrong happen. 
I've had no idea about the error. Can somebody explain to me why?
Last edited by anhldbk; September 23rd, 2010 at 02:02 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|