
How to handle 'error C2440'
Hello Esteemed Developers,
I am trying to develop basic TCP/IP Server-Client programs at the Visual C++ .NET, using Windows Forms Application(.NET) template. I coded the following code snippets:
FORM1.H
---------------------------------------------------------------------------------------------------------------------
public __gc class Form1 : public System::Windows::Forms::Form
{
...
public:
#define PORT 22222
#define IP_Addr "127.0.0.1"
SOCKET ServerSocket, ClientSocket;
sockaddr_in ServerSockAddrIn, ClientSockAddrIn;
WSADATA wsaData;
WORD wVersionRequested;
int retBindVal, retListenVal, retSendVal, retRecvVal, ClientSockAddrInLen;
...
public: void Start_Server();
...
}
---------------------------------------------------------------------------------------------------------------------
FORM1.cpp
---------------------------------------------------------------------------------------------------------------------
void Form1::Start_Server()
{
....
retBindVal = bind(ServerSocket,(sockaddr*) &ServerSockAddrIn, sizeof(ServerSockAddrIn)); //Error Msg #1
...
ClientSocket = accept(ServerSocket, (struct sockaddr*) &ClientSockAddrIn, &ClientSockAddrInLen); //Error Msg #2
...
}
---------------------------------------------------------------------------------------------------------------------
When I build the application it gives me the following errors
Error Msg #1: errorC2440: 'type cast' : cannot convert from 'sockaddr_in __gc*' to 'sockaddr*'
Error Msg #2: errorC2440: 'type cast' : cannot convert from 'sockaddr_in __gc*' to 'sockaddr*'
I guess that I should type cast unmanaged code to managed code. Please kindly guide me to solve this problem. I downloaded VC.NET Samples from microsoft.com. There are Socket samples in it, but they are not clear for me.
I am requesting your kind helps.
Thank you very much