char *sfilename, *dfilename;
LPBYTE buffer[3];
HANDLE sfile , dfile;
LPOVERLAPPED olOne = {NULL};
LPOVERLAPPED olTwo = {NULL};
LPOVERLAPPED_COMPLETION_ROUTINE ocr = {NULL};
if(sfilename != NULL)
{
CreateFile
(sfilename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVER
LAPPED,sfile);
DWORD err = GetLastError();
if(!ReadFileEx(sfile,buffer,2,olOne,ocr))
return false;
}
if(dfilename != NULL)
{
CreateFile
(dfilename,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_FLAG_OVERL
APPED,dfile);
if(!WriteFileEx(dfile,buffer,2,olTwo,ocr))
return false;
}
> CreateFile
>(sfilename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVER
>LAPPED,sfile);
Try this instead:
sfile = CreateFile
(sfilename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVER
LAPPED,NULL);
Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
All of your pointer allocations (char*, LP...) are incorrect. You are
allocating pointers containing garbage instead of allocating an object
and passing its address.
char sfilename[_MAX_PATH];
BYTE buffer[3];
OVERLAPPED olOne = {0};
The CreateFile result is returned by the function, but you are passing
sFile as a parameter.
sfile = CreateFile(....);
You are not passing the name of the file anywhere. Also if(sfilename !=
NULL) is testing the value of an uninitialized pointer, i.e. garbage.
--
Scott McPhillips [VC++ MVP]
char sfilename[60]; // source file path
char dfilename[60]; // destination file path
BYTE buffer[3];
HANDLE sfile , dfile; // source & destination file handles
LPOVERLAPPED olOne = {0};
LPOVERLAPPED olTwo = {0};
LPOVERLAPPED_COMPLETION_ROUTINE ocr = {0};
if(sfilename != NULL) // was path passed to method?
{
sfile = CreateFile
(sfilename,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_FLAG_OVER
LAPPED,NULL);
DWORD err = GetLastError();
if(!ReadFileEx(sfile,&buffer,2,olOne,ocr))
return false;
}
if(dfilename != NULL) // was path passed to method?
{
dfile = CreateFile
(dfilename,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_FLAG_OVERL
APPED,NULL);
if(!WriteFileEx(dfile,&buffer,2,olTwo,ocr))
return false;
}
Jim, you have pretty much the same kind of errors as before. You don't
seem to have a basic understanding of pointers, which are crucial in
most C/C++ programming.
In the case of the sfilename, it will never be NULL because it refers to
the address of the char array. I'm hesitant to suggest a fix because
you haven't shown anything about what is "passed to method". You need
to know what it being passed.
In the case of the OVERLAPPED structure you are allocating an
LPOVERLAPPED, which is only a pointer to an OVERLAPPED, which is the
same error you had before. You need to allocate an OVERLAPPED. Then
you pass &olOne (note the & address-of operator). The address of an
OVERLAPPED is an LPOVERLAPPED. In plain English, Windows needs you to
pass the address of something, but you are not creating the something.