Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SHFileOperation Win32 API function
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
SHFileOperation Win32 API function
Divers
Thread ID:
00279105
Message ID:
00279105
Vues:
67
I am trying to use the SHFileOperation Win32 API function to copy files from one place to another.

The SHFileOperation Win32 API function can be used to copy files exactly as the Windows Explorer does (i.e. the same dialog, flying "papers" animation, etc). It also allows the user to cancel the operation.

I am using the Struct class, written by Christof Lange and Mark Wilden , to help me in this process because the SHFileOperation uses a Structure.

When I run the program I get the following error "Declare DLL call caused an exception.".

Can somebody please give me some advice on what I am doing wrong.

Here is my Test Code:
*-- Operation to perform
*-- I got this information out of the shellapi.h file for Visual C++
#DEFINE FO_MOVE 0x0001
#DEFINE FO_COPY 0x0002
#DEFINE FO_DELETE 0x0003
#DEFINE FO_RENAME 0x0004

*-- Flags that control the file operation
*-- I got this information out of the shellapi.h file for Visual C++
#DEFINE FOF_CREATEPROGRESSDLG 0x0000 && handle to the parent window for the progress dialog box.
#DEFINE FOF_MULTIDESTFILES 0x0001 && The pTo member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited.
#DEFINE FOF_CONFIRMMOUSE 0x0002 && Not currently implemented.
#DEFINE FOF_SILENT 0x0004 && Does not display a progress dialog box.
#DEFINE FOF_RENAMEONCOLLISION 0x0008 && Give the file being operated on a new name in a move, copy, or rename operation if a file with the target name already exists.
#DEFINE FOF_NOCONFIRMATION 0x0010 && Respond with Yes to All for any dialog box that is displayed.
#DEFINE FOF_WANTMAPPINGHANDLE 0x0020 && If FOF_RENAMEONCOLLISION is specified, the hNameMappings member will be filled in if any files were renamed.
#DEFINE FOF_ALLOWUNDO 0x0040 && Preserve Undo information.
#DEFINE FOF_FILESONLY 0x0080 && Perform the operation on files only if a wildcard file name (*.*) is specified.
#DEFINE FOF_SIMPLEPROGRESS 0x0100 && Displays a progress dialog box but does not show the file names.
#DEFINE FOF_NOCONFIRMMKDIR 0x0200 && Does not confirm the creation of a new directory if the operation requires one to be created.
#DEFINE FOF_NOERRORUI 0x0400 && don't put up error UI
#DEFINE FOF_NOCOPYSECURITYATTRIBS 0x0800 && dont copy NT file Security Attributes

LOCAL loStruct, lcStruct, lnMainHWnd

SET LIBRARY TO HOME()+"FOXTOOLS" ADDITIVE

*-- Get the Visual FoxPro Main HWnd
lnMainHWnd = MainHwnd()

SET LIBRARY TO

*-- The Windows API provides the ability to perform a
*-- copy, move, rename, or delete operation on
*-- a file system object using the SHFileOperation API function
*-- exported by Shell32.dll.
DECLARE INTEGER SHFileOperation IN shell32.DLL STRING lpFileOp

SET CLASSLIB TO STRUCT

loStruct = CREATEOBJECT( "SHFILEOPSTRUCT")
loStruct.HWND = lnMainHWnd
loStruct.wFunc = FO_COPY
loStruct.pFrom = "\\Server1\Data\*.*"
loStruct.pTo = "c:\TempData"
loStruct.fFlags = FOF_NOCONFIRMATION
? SHFileOperation( loStruct.GetString() )
loStruct.RELEASE()

SET CLASSLIB TO

DEFINE CLASS shFileOpStruct AS STRUCT

CAPTION = "File Operation Structure"
WIDTH = 140
HWND = 0
wFunc = 0
pFrom = ""
pTo = ""
fFlags = 0
fAnyOperationsAborted = 0
hNameMappings = 0
lpszProgressTitle = ""
NAME = "shFileOpStruct"

PROCEDURE getcmembers
RETURN ;
"LONG l:hwnd," + ;
"LONG ul:wFunc," + ;
"STRING pz:pFrom," + ;
"STRING pz:pTo," + ;
"LONG l:fFlags," + ;
"BOOL l:fAnyOperationsAborted," + ;
"LONG pz:hNameMappings," + ;
"STRING pz:lpszProgressTitle"
ENDPROC

ENDDEFINE

*-- shFileOpStruct Structure
*-- typedef STRUCT _SHFILEOPSTRUCT{
*-- HWND HWND;
*-- UINT wFunc;
*-- LPCSTR pFrom;
*-- LPCSTR pTo;
*-- FILEOP_FLAGS fFlags;
*-- BOOL fAnyOperationsAborted;
*-- LPVOID hNameMappings;
*-- LPCSTR lpszProgressTitle;
*-- } shFileOpStruct, FAR *LPSHFILEOPSTRUCT;
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform