Esempio n. 1
0
        internal static void CopyValues(this VirtualRegistry virtualRegistry, VirtualKey sourceKey, KeyInfo sourceKeyInfo, VirtualKey destinationKey)
        {
            using (HGlobalPtr lpValueName = new HGlobalPtr((sourceKeyInfo.MaxValueNameLength + 1) * sizeof(char)),
                   lpcValueName = new HGlobalPtr(sizeof(int)),
                   lpReserved = new HGlobalPtr(IntPtr.Zero),
                   lpdwType = new HGlobalPtr(sizeof(int)),
                   lpvData = new HGlobalPtr(sourceKeyInfo.MaxValueLength),
                   lpcData = new HGlobalPtr(sizeof(int)))
            {
                for (uint i = 0; i < sourceKeyInfo.ValuesNumber; ++i)
                {
                    Marshal.WriteInt32(lpcValueName.Ptr, unchecked ((int)sourceKeyInfo.MaxValueNameLength) + 1);
                    Marshal.WriteInt32(lpcData.Ptr, unchecked ((int)sourceKeyInfo.MaxValueLength));
                    sourceKey.EnumValue(i, lpValueName.Ptr, lpcValueName.Ptr, lpReserved.Ptr, lpdwType.Ptr, lpvData.Ptr,
                                        lpcData.Ptr);

                    Win32Api.RegValueType valueType = (Win32Api.RegValueType)Marshal.ReadInt32(lpdwType.Ptr);

                    int currentValueLength     = Marshal.ReadInt32(lpcData.Ptr);
                    int currentValueNameLength = Marshal.ReadInt32(lpcValueName.Ptr);

                    string currentValueName = Marshal.PtrToStringUni(lpValueName.Ptr, currentValueNameLength);

                    destinationKey.SetValue(null, currentValueName, 0, valueType, lpvData.Ptr, currentValueLength);
                }
            }
        }