问题就下代码注释的,请哪位有大哥帮我下,谢谢了
ACCESSFILE_DATA是我自己定义的结构,如下:
typedef struct _ACCESSFILE_DATA
{
BOOL bResult;
DWORD dwLastError;
DWORD dwLen;
char szData[1024];
} ACCESSFILE_DATA;
下面是Upload的代码:
int nError;
char szPath[256];
DWORD dwWrite;
HANDLE hSendFile;
WCHAR wszPath[256];
CREATEFILE_PARAM param;
ACCESSFILE_DATA filedata;
memset(wszPath, 0, sizeof(wszPath));
memset(¶m, 0, sizeof(CREATEFILE_PARAM));
memset(&filedata, 0, sizeof(FINDFILE_DATA));
sprintf(szPath, "\\test.zip");
MultiByteToWideChar(CP_ACP, 0, szPath, strlen(szPath), param.szFileName, strlen(szPath));
param.dwDesiredAccess = GENERIC_WRITE;
param.dwShareMode = FILE_SHARE_WRITE;
param.dwCreationDisposition = CREATE_ALWAYS;
param.dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
if (MEPCClient_bCreateFile(m_pMEClient, ¶m, &filedata, &nError))
{
dwWrite = 0;
hSendFile = CreateFile(TEXT("test.zip"), GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hSendFile != INVALID_HANDLE_VALUE)
{
do
{
memset(&filedata, 0, sizeof(ACCESSFILE_DATA));
filedata.dwLen = 512;//这边我在Download用1024没有错,可是在这边就出错了?但是用512没有错!
//还有我想做下这样改进,要怎么做?
//当Upload第一次失败时,我就要把文件大小变成512,第一次我要用1024
ReadFile(hSendFile, filedata.szData, filedata.dwLen, &filedata.dwLen, NULL);
if (MEPCClient_bWriteFile(m_pMEClient, &filedata, &nError))
TRACE("bResult %d, dwLen %d\n", filedata.bResult, filedata.dwLen);
else
TRACE("Error %d\n", nError);
}
while (filedata.dwLen != 0 && filedata.bResult);
}
CloseHandle(hSendFile);
MEPCClient_bCloseFile(m_pMEClient, &filedata, &nError);
}
MEPCClient_bCreateFile( )是些什么函数?
不知道错误的时候就 Debug 看看每句代码执行的结果是什么,很快就能找出问题了,这里看不出来什么问题的。