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 / April 2007

Tip: Looking for answers? Try searching our database.

Shell32 COM and other question(s)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ondrej Psencik - 14 Apr 2007 20:01 GMT
Hi,

I have basically 2 question related to COM objects.

1) I am using in C# project (NET 2.0) Shell32 (so it is referenced in the
project) and I am using it to retrieve details of the file. The code is:

           FileInfo f = new FileInfo(path);
           Shell32.Shell shell = new Shell32.ShellClass();
           Shell32.Folder folder = shell.NameSpace(f.Directory.FullName);
           Shell32.FolderItem folderItem = folder.ParseName(f.Name);
           String s = folder.GetDetailsOf(folderItem, i); //where i is of
relevant value 0 - 36 or so

and the problem is that it is not working with the e.g. CD-ROM - i.e. is not
retrieving details of the file (e.g. author, picture size, ...). I read
somewhere in the inet that it is because this info is lost when not using
NTFS file system, but actually it is not true, because Microsoft Windows
Explorer shows the infomation when one select the file and let the explorer
display info about the file (yes also for CD-ROM). And in the MSDN docs
there is not written anything about such a limitation. Can anyone bring
enlightenment for me and save my soul, please?

2) If I use Shell32.Shell shell = new Shell32.ShellClass(); do I have to do
any explicit releasing of the COM resources or so? I read somewhere in the
inet (there are so many rumors in the inet) that I have to use
releasecomobject or something like method to release resources. (can you
provide link or explain lifecycle of this, please?)

-----------------------------------------------------------

I have also addinitional question which is not so suitable for topic of this
forum but rather core .net, the piece of program reads times of the
directory and I had to do following workaround for directories - very
uncomfortable (raises exception and some very strange date values) - does
anybody posses knowledge about this problem?

           try
           {
               creationtime = fi.CreationTime;
               lastwritetime = fi.LastWriteTime;
           }
           catch (ArgumentOutOfRangeException exc)
           {
               //ANOMALY for the directory, directoryinfo implementation is
faulty
               //so this is workaround
               creationtime = DateTime.Now;
               lastwritetime = DateTime.Now;
               log.Error("Out of Range exception raised for the time." +
fi.Name, exc);
           }
           Text = fi.Name;

           if (creationtime.Year == 1601)
           {
               creationtime = lastwritetime;
           }

Thank you for answers.

Ondrej Psencik
Michael Phillips, Jr. - 15 Apr 2007 16:11 GMT
> and the problem is that it is not working with the e.g. CD-ROM - i.e. is
> not retrieving details of the file (e.g. author, picture size, ...). I
[quoted text clipped - 4 lines]
> MSDN docs there is not written anything about such a limitation. Can
> anyone bring enlightenment for me and save my soul, please?

In order to retrieve metadata (e.g. author, picture size, ...) from a file,
you must obtain an IPropertySetStorage interface from the shell.

You use the shell method BindToStorage to get this interface.

> 2) If I use Shell32.Shell shell = new Shell32.ShellClass(); do I have to
> do any explicit releasing of the COM resources or so? I read somewhere in
> the inet (there are so many rumors in the inet) that I have to use
> releasecomobject or something like method to release resources. (can you
> provide link or explain lifecycle of this, please?)

There are two ways to work with COM in .Net.  Managed or Unmanaged.

In Unmanaged COM, all the rules of COM apply.  You are responsible for
reference counting and releasing intefaces when you no longer need them.

In Managed COM, a runtime callable wrapper is generated for the COM object.
The RCW is responsible for reference counting and managing the releasing of
the interfaces.

The online MSDN documentation explains all the details.  The topics worth
reviewing include the rules of COM,  RCW and System.Runtime.InteropServices.
Ondrej Psencik - 26 Apr 2007 13:35 GMT
Hi,

Unfortunately BindToStorage and enumerating properties is not doing what I
wanted, because It is retrieving only some properties
and not for example image properties (group Image) as they are seen if you
display file properties in explorer.
It is interesting that GetDetailsOf is working fine when retrieving
properties from hard drive, and from DVD it is
retieving nothing. But if you subst folder on DVD to e.g. Z: drive then
GetDetailsOf IS working on the file in this subst drive.
So there is something esoteric in GetDetailsOf .

Ondrej Psencik

>> and the problem is that it is not working with the e.g. CD-ROM - i.e. is
>> not retrieving details of the file (e.g. author, picture size, ...). I
[quoted text clipped - 28 lines]
> reviewing include the rules of COM,  RCW and
> System.Runtime.InteropServices.

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.