Home > Software engineering >  MFC UNICODE socket inet_addr () function LPWSTR real participation const char * parameter mismatch
MFC UNICODE socket inet_addr () function LPWSTR real participation const char * parameter mismatch

Time:10-05

I'm from IP controls access to the IP, but always appear this problem, the project will use UNICODE programming, so I ask you a great god is there any solution to
 
//load socket character
The UpdateData (TRUE);
UpdateWindow ();
WSADATA WSADATA;
Int err;
WVersionRequested=MAKEWORD (1, 1);
Err=WSAStartup (wVersionRequested, & amp; WsaData);
If (err!=0)
{
return;
}
If (LOBYTE (wsaData wVersion)!=1 | | HIBYTE (wsaData wVersion)!
=1){
WSACleanup ();
return;
}
//create a socket
SockClient=socket (AF_INET SOCK_STREAM, 0).
If (INVALID_SOCKET==sockClient)
{
MessageBox (_T (" socket creation failed!" ));
return ;
}
SOCKADDR_IN addrSrv;
Cstrings serv_addr.
Unsigned char * pIP;
DWORD dwIP;
((CIPAddressCtrl *) GetDlgItem (IDC_IPADDRESS1)) - & gt; GetAddress (dwIP);
PIP=(unsigned char *) & amp; DwIP;
//type does not match the problems
Serv_addr. The Format (L "% % u. % u. % u. U", * (pIP) + 3), * (pIP) + 2), * (pIP) + 1), * pIP);
//addrSrv sin_addr. S_un. S_addr=inet_addr (" 172.25.11.17 ");//the server's IP
AddrSrv. Sin_addr. S_un. S_addr=inet_addr (serv_addr. The GetBuffer (1));//conversion server IP address
AddrSrv. Sin_family=AF_INET;
//addrSrv sin_port=htons (11110);//the server port
AddrSrv. Sin_port=htons (_ttoi (mID_PORT));
The connect (sockClient, (SOCKADDR *) & amp; AddrSrv, sizeof (SOCKADDR));//send a connection request to the server

CodePudding user response:

If use MFC, why not use CSocket? Other associated with IP control directly linked into a dword,

CodePudding user response:

Convert unicode to char

CodePudding user response:

WCHAR turn char * *
WideCharToMultiByte ()

CodePudding user response:

I used the USES_CONVERSION;
In added T2A inet_addr function transformation, preliminary tests successfully

CodePudding user response:

Direct use CW2A API is the simplest
  • Related