Obsolete function used in getRegistryHandle

Asked by VSeven

In xmlRegistry.cs the function:

        public static int getRegistryHandle(RegistryKey registryKey)
        {
            Type type = registryKey.GetType();
            FieldInfo fieldInfo = type.GetField("hkey", BindingFlags.Instance | BindingFlags.NonPublic);
            System.Runtime.InteropServices.SafeHandle i = (System.Runtime.InteropServices.SafeHandle)fieldInfo.GetValue(registryKey);
            return ((IntPtr)i.DangerousGetHandle()).ToInt32();
        }

I believe should be changed to:

public static int getRegistryHandle(RegistryKey registryKey)
{
 Type type = registryKey.GetType();
 FieldInfo fieldInfo = type.GetField("hkey", BindingFlags.Instance | BindingFlags.NonPublic);
 System.Runtime.InteropServices.SafeHandle i = (System.Runtime.InteropServices.SafeHandle)fieldInfo.GetValue(registryKey);
 return i.DangerousGetHandle().ToInt32();
}

As i.DangerousGetHandle already returns a IntPtr and using a DirectCast should not be used to cast to the same value type. I've tested this change and don't see any issues with it.

-Allan

Question information

Language:
English Edit question
Status:
Answered
For:
Little Registry Cleaner Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Nick (ub3rst4r) said :
#1

Thanks! I have made the changes to the source code.

Can you help with this problem?

Provide an answer of your own, or ask VSeven for more information if necessary.

To post a message you must log in.