public static int GetNameDispId(UnsafeNativeMethods.IDispatch obj)
 {
     int num = -1;
     string[] rgszNames = null;
     ComNativeDescriptor instance = ComNativeDescriptor.Instance;
     bool succeeded = false;
     instance.GetPropertyValue(obj, "__id", ref succeeded);
     if (succeeded)
     {
         rgszNames = new string[] { "__id" };
     }
     else
     {
         instance.GetPropertyValue(obj, -800, ref succeeded);
         if (succeeded)
         {
             num = -800;
         }
         else
         {
             instance.GetPropertyValue(obj, "Name", ref succeeded);
             if (succeeded)
             {
                 rgszNames = new string[] { "Name" };
             }
         }
     }
     if (rgszNames != null)
     {
         int[] rgDispId = new int[] { -1 };
         Guid empty = Guid.Empty;
         if (System.Windows.Forms.NativeMethods.Succeeded(obj.GetIDsOfNames(ref empty, rgszNames, 1, SafeNativeMethods.GetThreadLCID(), rgDispId)))
         {
             num = rgDispId[0];
         }
     }
     return num;
 }