Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

shfileoperation  with complete exception

Posted on 2003-11-10
5
Medium Priority
?
456 Views
Last Modified: 2010-04-05
Hi i was wondering could you please give me a complete code in handling the exception of the shfileopearation api?
0
Comment
Question by:oracle_beginner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:jconde
ID: 9720343
Hi!

Maybe this will help:

uses
  Windows, SysUtils, ShellAPI, FileCtrl;

procedure SHCopyFile(hWndOwner: HWND; const SourceFile, TargetFile: string);
var Info: TSHFileOpStruct;
    Aborted : Bool;
begin
  Aborted := False;
  with Info do
  begin
    Wnd := hWndOwner;
    wFunc := FO_COPY;

{ From Microsoft's Help:
  wFunc = Operation to perform. This member can be one of the following values:
  FO_COPY Copies the files specified by pFrom to the location specified by pTo.
  FO_DELETE Deletes the files specified by pFrom (pTo is ignored).
  FO_MOVE Moves the files specified by pFrom to the location specified by pTo.
  FO_RENAME Renames the files specified by pFrom. }

    pFrom := pChar(SourceFile);
    pTo := pChar(TargetFile);
    fFlags := 0;
    fAnyOperationsAborted := Aborted;
  end;
  try
    SHFileOperation(Info);
  finally
    if Aborted then; { enact upon any user cancellations }
  end;
end;
0
 
LVL 7

Expert Comment

by:jconde
ID: 9720359
BTW, TSHFileOpStruct is defined in ShellAPI as follows:

TSHFileOpStruct = record
   Wnd: HWND;
   wFunc: UINT;
   pFrom: PAnsiChar;
   pTo: PAnsiChar;
   fFlags: FILEOP_FLAGS;
   fAnyOperationsAborted: BOOL;
   hNameMappings: Pointer;
   lpszProgressTitle: PAnsiChar;
 end;

0
 
LVL 6

Expert Comment

by:DaFox
ID: 9725065
oracle_beginner,

what kind of error do you want to handle? If you are not interested in one specific error try it like this:

if ShFileOperation(AFileOpStruct) <> 0 then
begin
  ShowMessage(SysErrorMessage(GetLastError));
  exit;
end;

Win32 APIs don't raise exceptions, they return result codes!

Markus
0
 

Author Comment

by:oracle_beginner
ID: 9738168
I would like to trap especially when no diskette is in the drive, diskfull and so on..
0
 
LVL 6

Accepted Solution

by:
DaFox earned 1000 total points
ID: 9738718
Then take a look at the System Error Codes page in the PSDK:

// ...
26 The specified disk or diskette cannot be accessed. ERROR_NOT_DOS_DISK
39 The disk is full. ERROR_HANDLE_DISK_FULL
112 There is not enough space on the disk. ERROR_DISK_FULL
// ...

Markus

PS: It seems like SHFileOperation doesn't fail (return value <> 0) when there's no disk in drive A:. You have to check it on your own.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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