在VC里借鉴了个网友做的服务器和客户端程序,想把客户端移植到EVC下面,出现了编译错误,请高手指点怎么改??
vc下的客户端程序部分代码是:
[code=C/C++][/code]
DWORD WINAPI CClientDlg::SocketSend(LPVOID lpParameter)
{
HWND hwnd = ((socksend*)lpParameter)->hwnd;
CString sendfname = ((socksend*)lpParameter)->sendfname;
DWORD dwip = ((socksend*)lpParameter)->dwip;
SOCKET socketsend = socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addSrv;
addSrv.sin_addr.S_un.S_addr = htonl(dwip);
addSrv.sin_family = AF_INET;
addSrv.sin_port = htons(8848);
if ((connect(socketsend,(SOCKADDR*)&addSrv,sizeof(SOCKADDR))) == SOCKET_ERROR) //连接
{
closesocket(socketsend);
PrintSystemMsg("连接服务器失败!");
return FALSE;
}
PrintSystemMsg("连接服务器成功!");
//声明文件发送本地变量
SOCKET_STREAM_FILE_INFO StreamFileInfo;
WIN32_FIND_DATA FindFileData;
BOOL bRET = true;
BYTE * sendData = NULL;
CFile sendFile;
CFileException fe;
BOOL bFileISopen = FALSE;
UINT dwRead = 0;
//打开文件
if(!(bFileISopen = sendFile.Open(sendfname,CFile::modeRead | CFile::typeBinary,&fe)))
{
PrintSystemMsg("文件打开失败!请重试!");
goto free;
}
FindClose(FindFirstFile(sendfname,&FindFileData));
memset(&StreamFileInfo,0,sizeof(SOCKET_STREAM_FILE_INFO));
strcpy(StreamFileInfo.szFileTitle,sendFile.GetFileTitle());
StreamFileInfo.dwFileAttributes = FindFileData.dwFileAttributes;
StreamFileInfo.ftCreationTime = FindFileData.ftCreationTime;
StreamFileInfo.ftLastAccessTime = FindFileData.ftLastAccessTime;
StreamFileInfo.ftLastWriteTime = FindFileData.ftLastWriteTime;
StreamFileInfo.nFileSizeHigh = FindFileData.nFileSizeHigh;
StreamFileInfo.nFileSizeLow = FindFileData.nFileSizeLow;
PrintSystemMsg("开始发送文件.......");
if(send(socketsend,(const char*)&StreamFileInfo,sizeof(SOCKET_STREAM_FILE_INFO),0) == SOCKET_ERROR)
{
PrintSystemMsg("文件信息传送失败!请重试");
goto free;
}
//发送文件
while (dwRead<StreamFileInfo.nFileSizeLow)
{
byte * data = new byte[1024];
UINT dw = sendFile.Read(data,1024);
if ((send(socketsend,(const char*)data,1024,0)) == SOCKET_ERROR)
{
PrintSystemMsg("文件传输错误!可能网络断开!");
//closesocket(socketsend);
goto free;
}
dwRead+=dw;
delete[] data;
}
PrintSystemMsg("文件发送完毕");
AfxMessageBox("发送成功!");
free:
delete[] sendData;
if (bFileISopen)
{
sendFile.Close();
}
closesocket(socketsend);
WSACleanup();
return bRET;
}
移植到EVC下的代码是:
[code=C/C++][/code]
DWORD WINAPI CFileTranDlg::SocketSend(LPVOID lpParameter)
{
HWND hwnd = ((socksend*)lpParameter)->hwnd;
CString sendfname = ((socksend*)lpParameter)->sendfname;
DWORD dwip = ((socksend*)lpParameter)->dwip;
SOCKET socketsend = socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addSrv;
addSrv.sin_addr.S_un.S_addr = htonl(dwip);
addSrv.sin_family = AF_INET;
addSrv.sin_port = htons(6000);
if ((connect(socketsend,(SOCKADDR*)&addSrv,sizeof(SOCKADDR))) == SOCKET_ERROR) //连接
{
closesocket(socketsend);
PrintSystemMsg(_T("Connect Serve Fail!"));
return FALSE;
}
PrintSystemMsg(_T("Connect Serve Successful!"));
//声明文件发送本地变量
SOCKET_STREAM_FILE_INFO StreamFileInfo;
WIN32_FIND_DATA FindFileData;
BOOL bRET = true;
BYTE * sendData = NULL;
CFile sendFile;
CFileException fe;
BOOL bFileISopen = FALSE;
UINT dwRead = 0;
//打开文件
if(!(bFileISopen = sendFile.Open(sendfname,CFile::modeRead | CFile::typeBinary,&fe)))