Shell32 COM and other question(s) - DOTNET
This is a discussion on Shell32 COM and other question(s) - DOTNET ; 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 ...
-
Shell32 COM and other question(s)
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
-
Re: Shell32 COM and other question(s)
> 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.
-
Re: Shell32 COM and other question(s)
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@nospam.jun0.c0m> wrote in message
news:uJVTbB3fHHA.4552@TK2MSFTNGP04.phx.gbl...
>> 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.
>
Similar Threads
-
By Application Development in forum labview
Replies: 2
Last Post: 08-29-2007, 12:10 PM
-
By Application Development in forum Clipper
Replies: 5
Last Post: 07-06-2007, 03:27 AM
-
By Application Development in forum Clarion
Replies: 6
Last Post: 04-25-2005, 03:37 PM
-
By Application Development in forum Clarion
Replies: 0
Last Post: 04-21-2005, 03:07 PM
-
By Application Development in forum Java
Replies: 0
Last Post: 11-30-2003, 11:43 AM