?
Solved

using CopyFileEx.....identifier not found

Posted on 2004-11-04
5
Medium Priority
?
1,384 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:richjo100
  • 3
  • 2
5 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 400 total points
ID: 12492546
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
 

Author Comment

by:richjo100
ID: 12493991
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
 
LVL 48

Accepted Solution

by:
AlexFM earned 400 total points
ID: 12504144
Callback function should be global. If it is class member, it should be static.
0
 

Author Comment

by:richjo100
ID: 12505746
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
 

Author Comment

by:richjo100
ID: 12506118
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question