protected string GetName(UCOMIMoniker 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);
var ret = val as string;
if (string.IsNullOrEmpty(ret))
throw new NotImplementedException("Device FriendlyName");
return (ret);
}
catch (Exception)
{
return ("");
}
finally
{
bag = null;
if (bagObj != null)
Marshal.ReleaseComObject(bagObj); bagObj = null;
}
}