using CopyFileEx.....identifier not found

Hi all,

I am trying to use CopyFIleEx so that when i copy a file I get some feedback which I can use to update a progress bar. I think I have set up the CopyProgressRoutine correctly however I am having trouble with the FileCopyEx function.

I get an error C3861 'CopyFileEx' identifier not found.....

I have surfed the interenet and see I have to include the Kernel32.dll which I have tried by doing import "kernel32.dll" as well as adding it to the project from the visual studio "insert existing items.." menu. Both ways either error or dont find the CopyFileEx. I can use CopyFile fine but not CopyFileEx!

Why wont Visual Studio see it?

Thanks in advance
Rich
richjo100Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
CopyFileEx requirements:

Windows NT/2000 or later: Requires Windows NT 4.0 or later.
Windows 95/98/Me: Unsupported.

To compile function which has special OS requirements you need to define preprocessor constants, as described here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp

Add line
#define _WIN32_WINNT 0x0400
to the beginning of stdafx.h file and rebuild the project.
0
richjo100Author Commented:
Hi AlexFM
Thanks for teh reply.
I have done what you said and it worked.

Still a bit stuck on CopyFIleEx though. I dont think Im copying the address of the return  correctly.
Could you please help

=============================
........
   return CopyFileEx(source, fileNameToWrite, CopyProgressRoutine , 0, true,   COPY_FILE_FAIL_IF_EXISTS);      
}

private: DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize,   LARGE_INTEGER TotalBytesTransferred,  LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber,        DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) {

return PROGRESS_CONTINUE;

}


=======================

I am doing the simpliest thign I can in that I just return PROGRESS_CONTINUE. The error is to do wiht conversion form DWORD to LPPROGRESS_ROUTINE. I jsut think I have got my addresses muddled up

Richard
0
AlexFMCommented:
Callback function should be global. If it is class member, it should be static.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
richjo100Author Commented:
Hi AlexFM. Thanks for the reply. The code is now:

=====================

 return CopyFileEx(source, fileNameToWrite, CopyProgressRoutine, 0,  true, COPY_FILE_FAIL_IF_EXISTS);      
}

public: static DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred,        LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData) {

      return PROGRESS_CONTINUE;

}


=====================


I still get the same error though. It is

d:\Rich\Work\X_SEND MESSING\version6\XSend\Form1.h(382): error C2664: 'CopyFileExA' : cannot convert parameter 3 from 'DWORD (LARGE_INTEGER,LARGE_INTEGER,LARGE_INTEGER,LARGE_INTEGER,DWORD,DWORD,HANDLE,HANDLE,LPVOID)' to 'LPPROGRESS_ROUTINE'

Thanks for your help so far

Richard
0
richjo100Author Commented:
Hi

Solved it......here is my code


===============

.....
BOOL b = 1;
return  CopyFileEx(source, fileNameToWrite, (LPPROGRESS_ROUTINE) CopyProgressRoutine, 0, &b, COPY_FILE_FAIL_IF_EXISTS);      
}
      
static DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred,  LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber,  DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData)      {

       return PROGRESS_CONTINUE;
    }

===========================

Thanks for your help AlexFM
THe points are yours

Richard
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.