private string GetName( IMoniker moniker )
{
Object bagObj = null;
IPropertyBag bag = null;
try
{
Guid bagId = typeof( IPropertyBag ).GUID;
// get property bag of the moniker
moniker.BindToStorage( null, null, ref bagId, out bagObj );
bag = (IPropertyBag) bagObj;
// read FriendlyName
object val = "";
int hr = bag.Read( "FriendlyName", ref val, IntPtr.Zero );
if ( hr != 0 )
Marshal.ThrowExceptionForHR( hr );
// get it as string
string ret = (string) val;
if ( ( ret == null ) || ( ret.Length < 1 ) )
throw new ApplicationException( );
return ret;
}
catch ( Exception )
{
return "";
}
finally
{
// release all COM objects
bag = null;
if ( bagObj != null )
{
Marshal.ReleaseComObject( bagObj );
bagObj = null;
}
}
}