BOOL WriteFile(
HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure for overlapped I/O
);
请问第二个参数该怎么用??我想把一缓冲器(INbuffer)中的数据写入一文件,但不知第二个参数是什么意思,请问我该怎么把INbuffer中数据写入文件??
HANDLE hFile, // handle to file to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // pointer to structure for overlapped I/O
);
请问第二个参数该怎么用??我想把一缓冲器(INbuffer)中的数据写入一文件,但不知第二个参数是什么意思,请问我该怎么把INbuffer中数据写入文件??
解决方案 »
- GetKeyState和GetAsyncKeyState 在服务中调用返回0,getlasterror提示是5,是什么问题?
- 求救
- 我碰到这样一个ActiveX ocx的事件问题:
- 在对话框程序中调用文档视图结构实现打印,但打印预览里的打印按钮不能实现打印,怎么办?
- 用CArchive,写入大概4万条记录,形成20多兆的序列化文件,这个过程很快,但用CArchive读出要7秒,正常吗?
- 请问有谁知道怎样从视频采集卡中采集保存YUV格式的图像数据,用Directshow可以吗?
- 这串字符如何解析????????????
- 如何在dll中使用custom control控件?如何妥善分配各个dll中资源不冲突?
- CHtmlView 编程的问题
- 用MFC來做啥?
- ado连接oracle的问题!
- WriteFile问题!!大家帮忙看看!我在这谢过了.
//#include <windows.h>
#include <stdio.h>
#include <stdlib.h> /* For _MAX_PATH definition */
#include <conio.h>static BOOL MyCopyFile(HANDLE hSource,HANDLE hDestination);int main(int argc, char* argv[])
{
HANDLE hstdOut,hstdIn;
HANDLE hSource,hDestination;
DWORD dwWritten;
char szSourceFile[_MAX_PATH],szDestFile[_MAX_PATH];
char szMsgBuf[255];
WIN32_FIND_DATA FindData;
HANDLE hFind; hstdOut = GetStdHandle(STD_OUTPUT_HANDLE);
hstdIn = GetStdHandle(STD_INPUT_HANDLE);
if(hstdOut==INVALID_HANDLE_VALUE || hstdIn==INVALID_HANDLE_VALUE)
{
return -1;
} if (argc !=3)
{
sprintf(szMsgBuf,"\nParameter Error!\nPlease use as: CopyEx SourceFile DestinationFile\n");
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
return -1;
}
strcpy(szSourceFile,argv[1]);
strcpy(szDestFile,argv[2]); /*查找源文件是否存在*/
memset(&FindData,0X00,sizeof(WIN32_FIND_DATA));
hFind = FindFirstFile(szSourceFile,&FindData);
if(hFind == INVALID_HANDLE_VALUE)
{
sprintf(szMsgBuf,"\nFile %s Isn't Exist!\n",szSourceFile);
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
return -1;
}
FindClose(hFind); /*查找目标文件是否存在*/
memset(&FindData,0X00,sizeof(WIN32_FIND_DATA));
hFind = FindFirstFile(szDestFile,&FindData);
if(hFind != INVALID_HANDLE_VALUE)
{
DWORD dwRead=10;
char Key; sprintf(szMsgBuf,"\nFile %s Exist!Relpace It?(Y/N)",szDestFile);
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
//ReadFile(hstdIn,szRead,dwRead,&dwRead,NULL); Key=_getch();
Key=toupper(Key);
if (Key!='Y')
{
sprintf(szMsgBuf,"\nTerminate Operation\n");
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
return 0;
}
}
FindClose(hFind); hSource = CreateFile(
szSourceFile,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL); if (hSource==INVALID_HANDLE_VALUE)
{
sprintf(szMsgBuf,"\nOpen %s File Failed!\n",szSourceFile);
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
return -1;
}
hDestination = CreateFile(
szDestFile,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hSource==INVALID_HANDLE_VALUE)
{
sprintf(szMsgBuf,"\nOpen %s File Failed!\n",szDestFile);
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
CloseHandle(hSource);
return -1;
} sprintf(szMsgBuf,"\nStart Copy File %s To File %s \n ...... ......\n",szSourceFile,szDestFile);
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
if(!MyCopyFile(hSource,hDestination))
{
sprintf(szMsgBuf,"\nCopy File Failed!\n");
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL);
CloseHandle(hSource);
CloseHandle(hDestination);
return -1;
}
sprintf(szMsgBuf,"\nCopy File Succeeded!\n");
WriteFile(hstdOut,szMsgBuf,lstrlen(szMsgBuf),&dwWritten,NULL); CloseHandle(hSource);
CloseHandle(hDestination);
return 0;
}static BOOL MyCopyFile(HANDLE hSource,HANDLE hDestination)
{
DWORD dwReadCount;
DWORD dwFileSize;
CHAR szReadBuf[1000]; dwFileSize = GetFileSize(hSource,NULL);
dwReadCount = 0;
while(dwFileSize>dwReadCount)
{
DWORD dwWriteSize=0;
DWORD dwReadSize=1000; //每次读1000个字节
if(!ReadFile(hSource,szReadBuf,dwReadSize,&dwReadSize,NULL))
{
return FALSE;
}
dwWriteSize = dwReadSize;
if(!WriteFile(hDestination,szReadBuf,dwWriteSize,&dwWriteSize,NULL))
{
return FALSE;
}
else
{
dwReadCount += dwReadSize;
}
}
return TRUE;
}
-------------------------------------------------------
楼主,你把缓冲器中得数据指针作为第二个参数传入
至于第二个参数得含义,他得注释写得很清楚了
pointer to data to write to file
即:要写入文件得数据指针
HANDLE hFile, // 文件的句柄,用OpenFile产生
LPCVOID lpBuffer, // 要写入的数据的内存,就是你的INbuffer
DWORD nNumberOfBytesToWrite, // INbuffer的长度
LPDWORD lpNumberOfBytesWritten, // 实际写入的长度
LPOVERLAPPED lpOverlapped // pointer to structure for overlapped I/O
);
这样写出错啊,错误信息是:
error C2664: 'WriteFile' : cannot convert parameter 2 from 'class std::list<char,class std::allocator<char> >' to 'const void *'什么原因啊??谢谢!
---------------
类型错误
转化成char数组试试