Esempio n. 1
0
    //  Read a System.string  from the registry.
    public bool GetValue(string strKeyName,
                         string strValueName,
                         ref string strValue)
    {
        //  Open HKEY_LOCAL_MACHINE\SOFTWARE\YaoDurant\...
        //     and have its handle placed in hkeyCurrent.
        intReturn =
            WinRegCE.RegCreateKeyEx(hkeyHive,
                                    strYDKey + @"\" + strKeyName,
                                    0, string.Empty, 0, 0,
                                    IntPtr.Zero,
                                    ref hkeyCurrent,
                                    ref regdispResult);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Create fields to hold the output.
        StringBuilder sbValue = new StringBuilder(cbMAX);
        int           cbValue = cbMAX;

        //  Read the value from the registry into sbValue
        WinRegCE.REGTYPE rtType = 0;
        intReturn =
            WinRegCE.RegQueryValueEx(hkeyCurrent, strValueName,
                                     0, ref rtType,
                                     sbValue, ref cbValue);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Close the key.
        intReturn = WinRegCE.RegCloseKey(hkeyCurrent);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Set the string into the output parameter.
        strValue = sbValue.ToString();

        return(true);
    }
Esempio n. 2
0
    //  Read a System.int from the registry.
    public bool GetValue(string strKeyName,
                         string strValueName,
                         ref int intValue)
    {
        //  Open HKEY_LOCAL_MACHINE\SOFTWARE\YaoDurant\...
        intReturn =
            WinRegCE.RegCreateKeyEx(hkeyHive,
                                    strYDKey + @"\" + strKeyName,
                                    0, string.Empty, 0, 0,
                                    IntPtr.Zero,
                                    ref hkeyCurrent,
                                    ref regdispResult);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Pull the value into intValue.  For platform
        //     independence, use Marshal.SizeOf(intValue),
        //     not "4", to specify the size in bytes of
        //     a System.int.
        int cbValue = Marshal.SizeOf(intValue);

        WinRegCE.REGTYPE rtType = 0;
        intReturn =
            WinRegCE.RegQueryValueEx(hkeyCurrent, strValueName,
                                     0, ref rtType,
                                     ref intValue, ref cbValue);
        if (intReturn != 0)
        {
            return(false);
        }

        //  Close the key.
        intReturn = WinRegCE.RegCloseKey(hkeyCurrent);
        if (intReturn != 0)
        {
            return(false);
        }

        return(true);
    }