Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / July 2004

Tip: Looking for answers? Try searching our database.

P/Invoke to Shell32 SHFileOperation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Reed - 26 Jul 2004 10:01 GMT
SHI am trying to use the Shell32 operation FileOperation to send a file to the recycling Bin.  I have defined the structure in my class as follows and am hoping my definition is correct.  Please let me know if I have it correct:

   [StructLayout(LayoutKind.Sequential)]
     internal struct _SHFILEOPSTRUCT
   {
     public IntPtr hwnd;
     public Int32 wFunc;
     [MarshalAs(UnmanagedType.LPStr)]
     public String pFrom;
     [MarshalAs(UnmanagedType.LPStr)]
     public String pTo;
     public Int32 fFlags;
     public Int32 fAnyOperationsAborted;
     public IntPtr hNameMappings;
     [MarshalAs(UnmanagedType.LPStr)]
     public String lpszProgressTitle;
   }

   internal enum FileOpFunc
   {
     Delete = 3
   }
   
   internal enum FileOpFlags
   {
     Silent=0x04,
     AllowUndo=0x40,
     NoConfirmation=0x10
   }

   [DllImport("Shell32.dll")]
   internal static extern Int32 SHFileOperation(ref _SHFILEOPSTRUCT fileOp);

Sometimes when I call it I get a failure response of 1026 (0x402).  Sometimes it works.  Does anyone know what this response value is?
BMermuys - 26 Jul 2004 12:19 GMT
Hi,
inline,
> SHI am trying to use the Shell32 operation FileOperation to send a file to the recycling Bin.  I have defined the structure in my class as follows and
am hoping my definition is correct.  Please let me know if I have it
correct:

>     [StructLayout(LayoutKind.Sequential)]
>       internal struct _SHFILEOPSTRUCT
[quoted text clipped - 26 lines]
>     [DllImport("Shell32.dll")]
>     internal static extern Int32 SHFileOperation(ref _SHFILEOPSTRUCT fileOp);

How do you call it? Some struct fields must be 'double null terminated', eg.

   aFileOpStruct.pFrom = "test.txt\0test2.txt\0";
   aFileOpStruct.pFrom = "test.txt\0";

C# will add the second null to the end when marshalling.

HTH,
greetings

> Sometimes when I call it I get a failure response of 1026 (0x402).  Sometimes it works.  Does anyone know what this response value is?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.