我在使用 memcpy 时遇到了一些麻烦,因为当执行 memcpy 操作时,我得到:
"ÍÍWF03-021913.datýýý««««««««þ"
当我应该得到:
“WF03-021913.datýýý«««««««««þ”
我不知道这些领先的“ÍÍ”是从哪里来的。
代码:
注意:lpszFileName = "WF03-021913.dat"
typedef struct {
BYTE cbRequestType;
BYTE cbFileName;
char* szFileName;
} UFTP_GET_FILE_INFO_REQUEST;
BOOL Uftp_BuildFileInfoRequest(PUFTP_REQUEST request, LPCTSTR lpszFileName)
{
UFTP_GET_FILE_INFO_REQUEST *fileInfo;
int fileNameLen;
if (lpszFileName == NULL) {
ASSERT( 0 );
return FALSE;
}
fileNameLen = strlen( lpszFileName );
if (fileNameLen == 0)
return FALSE;
request->dwRequestSize = sizeof(UFTP_GET_FILE_INFO_REQUEST) -
sizeof(void*) + fileNameLen;
request->RequestBuffer = malloc( request->dwRequestSize );
if ( !request->RequestBuffer ) {
TRACE0("Failed to allocate RequestBuffer");
return FALSE;
}
fileInfo = (UFTP_GET_FILE_INFO_REQUEST*) request->RequestBuffer;
fileInfo->cbRequestType = UFTP_GET_FILE_INFO;
fileInfo->cbFileName = fileNameLen;
memcpy(&fileInfo->szFileName, lpszFileName, fileNameLen);
return TRUE;
}