HighTechTalks DotNet Forums  

Shell32 COM and other question(s)

Dotnet Framework (Interop) microsoft.public.dotnet.framework.interop


Discuss Shell32 COM and other question(s) in the Dotnet Framework (Interop) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ondrej Psencik
 
Posts: n/a

Default Shell32 COM and other question(s) - 04-14-2007 , 03:01 PM






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




Reply With Quote
  #2  
Old   
Michael Phillips, Jr.
 
Posts: n/a

Default Re: Shell32 COM and other question(s) - 04-15-2007 , 11:11 AM






Quote:
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?
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.

Quote:
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.




Reply With Quote
  #3  
Old   
Ondrej Psencik
 
Posts: n/a

Default Re: Shell32 COM and other question(s) - 04-26-2007 , 08:35 AM



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


"Michael Phillips, Jr." <mphillips53 (AT) nospam (DOT) jun0.c0m> wrote

Quote:
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?

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.





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.