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