Save registry values ​​in WinCE using C # application

I am working on a WinCE 6.0 system with a touch screen that stores calibration data (xy location, offset, etc.) in the system registry (HKLM \ HARDWARE \ TOUCH). Right now, I am putting cal values ​​in registry keys that fall into the OS image during build. This works great for the monitor from which I get the original cal values, but when I download this image to another system with a different monitor, the location of the touch screen pointer is (understandably) turned off because the two monitors do not have the same cal values.

My problem is that I do not know how to store values ​​in the registry correctly so that they are saved after the force cycle. Look, I can recalibrate the screen in the second system, but new values ​​exist only in volatile memory. I suggested to my boss that we can simply tell our client to always leave power on the device - this did not work out well.

I need advice on how to save new constants in the registry so that we can calibrate the monitors once before sending them to our client, and I do not need to create separate OS images for each module we create.

The C # method, which is known to work in CE6.0, will be useful. Thank.

-Odbasta p>

+3
source share
3 answers

, , , Flush RegistryKey. ( ), , , :

http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.flush.aspx

.NET Compact Framework 2.0 .

+3

:

DannySmurf, , . , , , . , :

  • , RAM, . .
  • , . platform.reg:

    [HKEY_LOCAL_MACHINE\init\BootVars]
    "SystemHive"="\\Hard Disk\\system.hv"
    "ProfileDir"="\\Documents and Settings"
    "RegistryFlags"=dword:1               ; Flush hive on every RegCloseKey call
    "SystemHiveInitialSize"=dword:19000   ; Initial size for hive-registry file 
    "Start DevMgr"=dword:1
    
  • system.hv (CF- ), . , system.hv HKLM.

  • , , , REG . , , (PCMCIA) , . - :

    ;HIVE BOOT SECTION
    [HKEY_LOCAL_MACHINE\Drivers\PCCARD\PCMCIA\TEMPLATE\PCMCIA]
      "Dll"="pcmcia.dll"
      "NoConfig"=dword:1
      "IClass"=multi_sz:"{6BEAB08A-8914-42fd-B33F-61968B9AAB32}=PCMCIA Card Services"
      "Flags"=dword:1000
    ;END HIVE BOOT SECTION
    

, , .

+5

, , . , .

Microsoft.Win32;

    /// <summary>
    /// store a key value in registry. if it don't exist it will be created. 
    /// </summary>
    /// <param name="mainKey">the main key of key path</param>
    /// <param name="subKey">the path below the main key</param>
    /// <param name="keyName">the key name</param>
    /// <param name="value">the value to be stored</param>
    public static void SetRegistry(int mainKey, String subKey, String keyName, object value)
    {
        if (mainKey != CURRENT_USER && mainKey != LOCAL_MACHINE)
        {
            throw new ArgumentOutOfRangeException("mainKey", "\'mainKey\' argument can only be AppUtils.CURRENT_USER or AppUtils.LOCAL_MACHINE values");
        }

        if (subKey == null)
        {
            throw new ArgumentNullException("subKey", "\'subKey\' argument cannot be null");
        }

        if (keyName == null)
        {
            throw new ArgumentNullException("keyName", "\'keyName\' argument cannot be null");
        }

        const Boolean WRITABLE = true;
        RegistryKey key = null;

        if (mainKey == CURRENT_USER)
        {
            key = Registry.CurrentUser.OpenSubKey(subKey, WRITABLE);

            if (key == null)
            {
                key = Registry.CurrentUser.CreateSubKey(subKey);
            }
        }
        else if (mainKey == LOCAL_MACHINE)
        {
            key = Registry.LocalMachine.OpenSubKey(subKey, WRITABLE);

            if (key == null)
            {
                key = Registry.LocalMachine.CreateSubKey(subKey);
            }
        }

        key.SetValue(keyName, value);

    }

    /// <summary>
    /// find a key value in registry. if it don't exist the default value will be returned.
    /// </summary>
    /// <param name="mainKey">the main key of key path</param>
    /// <param name="subKey">the path below the main key</param>
    /// <param name="keyName">the key name</param>
    /// <param name="defaultValue">the value to be stored</param>

    public static object GetRegistry(int mainKey, String subKey, String keyName, object defaultValue)
    {
        if (mainKey != CURRENT_USER && mainKey != LOCAL_MACHINE)
        {
            throw new ArgumentOutOfRangeException("mainKey", "\'mainKey\' argument can only be AppUtils.CURRENT_USER or AppUtils.LOCAL_MACHINE values");
        }

        if (subKey == null)
        {
            throw new ArgumentNullException("subKey", "\'subKey\' argument cannot be null");
        }

        if (keyName == null)
        {
            throw new ArgumentNullException("keyName", "\'keyName\' argument cannot be null");
        }

        RegistryKey key = Registry.CurrentUser.OpenSubKey(subKey);

        if (mainKey == CURRENT_USER)
        {
            key = Registry.CurrentUser.OpenSubKey(subKey);
        }
        else if (mainKey == LOCAL_MACHINE)
        {
            key = Registry.LocalMachine.OpenSubKey(subKey);
        }

        object result = defaultValue;

        if (key != null)
        {
            result = key.GetValue(keyName, defaultValue);
        }

        return result;
    }
0

Source: https://habr.com/ru/post/1696823/


All Articles