How to handle 'error C2440'

G

Guest

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.
--------------------------------------------------------------------------------------------------------------------
public __gc class Form1 : public System::Windows::Forms::For

..
public
#define PORT 2222
#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.cp
--------------------------------------------------------------------------------------------------------------------
void Form1::Start_Server(

...
retBindVal = bind(ServerSocket,(sockaddr*) &ServerSockAddrIn, sizeof(ServerSockAddrIn)); //Error Msg #
..
ClientSocket = accept(ServerSocket, (struct sockaddr*) &ClientSockAddrIn, &ClientSockAddrInLen); //Error Msg #
..

--------------------------------------------------------------------------------------------------------------------

When I build the application it gives me the following error
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
 
A

auburnate

I'm also interested in fixing this error. Does anyone know how t
convert from 'unsigned short [19]' to 'char' .

Nat


-
auburnat
 
D

David Olsen

auburnate said:
I'm also interested in fixing this error. Does anyone know how to
convert from 'unsigned short [19]' to 'char' .

There is no meaningful conversion from 'unsigned short [19]' to 'char'.
To be of any help, we need to know what kind of object you have, and why
the compiler thinks it needs to convert it to 'char'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top