首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > WinCE >

一个文件传输有关问题,高手请指点啊

2012-02-27 
请教高手一个文件传输问题,高手请指点啊!在VC里借鉴了个网友做的服务器和客户端程序,想把客户端移植到EVC

请教高手一个文件传输问题,高手请指点啊!
在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_INFOStreamFileInfo;
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_INFOStreamFileInfo;
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(_T("Open File Fail!Please again!"));
goto free;
}

FindClose(FindFirstFile(sendfname,&FindFileData));
memset(&StreamFileInfo,0,sizeof(SOCKET_STREAM_FILE_INFO));
// CString str = sendFile.GetFileTitle();
// CString temp = _T("");
// temp.Format(_T("%s"),str);
// wcscpy(StreamFileInfo.szFileTitle,temp);//修改!!!!
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(_T("Start Senf File...."));

if(send(socketsend,(const char*)&StreamFileInfo,sizeof(SOCKET_STREAM_FILE_INFO),0) == SOCKET_ERROR)
{

PrintSystemMsg(_T("File Infor Tran Fail!Please again"));
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(_T("File Tran Error!Maybe net disconnect!"));
//closesocket(socketsend);
goto free;
}
dwRead+=dw;
delete[] data;
}

PrintSystemMsg(_T("File Send Successful!"));
AfxMessageBox(_T("Send Successful!"));

free:

delete[] sendData;
if (bFileISopen)
{
sendFile.Close();
}
closesocket(socketsend);
WSACleanup();  
return bRET;
}

出现了如下编译错误:
Deleting intermediate files and output files for project 'FileTran - Win32 (WCE emulator) Debug'.
--------------------Configuration: FileTran - Win32 (WCE emulator) Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
FileTran.cpp
FileTranDlg.cpp
Generating Code...
Linking...
FileTranDlg.obj : error LNK2019: unresolved external symbol _inet_addr referenced in function "protected: void __thiscall CFileTranDlg::OnSend(void)" (?OnSend@CFileTranDlg@@IAEXXZ)
FileTranDlg.obj : error LNK2019: unresolved external symbol _WSACleanup referenced in function "public: static unsigned long __cdecl CFileTranDlg::SocketSend(void *)" (?SocketSend@CFileTranDlg@@SAKPAX@Z)
FileTranDlg.obj : error LNK2019: unresolved external symbol _send referenced in function "public: static unsigned long __cdecl CFileTranDlg::SocketSend(void *)" (?SocketSend@CFileTranDlg@@SAKPAX@Z)
FileTranDlg.obj : error LNK2019: unresolved external symbol _closesocket referenced in function "public: static unsigned long __cdecl CFileTranDlg::SocketSend(void *)" (?SocketSend@CFileTranDlg@@SAKPAX@Z)
FileTranDlg.obj : error LNK2019: unresolved external symbol _connect referenced in function "public: static unsigned long __cdecl CFileTranDlg::SocketSend(void *)" (?SocketSend@CFileTranDlg@@SAKPAX@Z)
FileTranDlg.obj : error LNK2019: unresolved external symbol _htons referenced in function "public: static unsigned long __cdecl CFileTranDlg::SocketSend(void *)" (?SocketSend@CFileTranDlg@@SAKPAX@Z)
FileTranDlg.obj : error LNK2019: unresolved external symbol _htonl referenced in function "public: static unsigned long __cdecl CFileTranDlg::SocketSend(void *)" (?SocketSend@CFileTranDlg@@SAKPAX@Z)
FileTranDlg.obj : error LNK2019: unresolved external symbol _socket referenced in function "public: static unsigned long __cdecl CFileTranDlg::SocketSend(void *)" (?SocketSend@CFileTranDlg@@SAKPAX@Z)
emulatorDbg/FileTran.exe : fatal error LNK1120: 8 unresolved externals


Error executing link.exe.
Creating browse info file...

FileTran.exe - 9 error(s), 0 warning(s)


[解决办法]
windows下用socket是包含库Ws2_32.lib,wince下是包含Ws2.lib,两个库名字不一样,是否没改?
[解决办法]
EVC是平台吗?它只是开发工具。

LZ用的是什么SDK呢?
[解决办法]
加入对Ws2.lib的连接在
setting中

热点排行