Читаем Программирование КПК и смартфонов на .NET Compact Framework полностью

   try {

    int result = RegOpenKeyEx(root, keyName, 0, KeyAccess.None, ref hkey);

    if (ERROR_SUCCESS != result) return result;

    byte[] bytes = null;

    uint length = 0;

    KeyType keyType = KeyType.None;

    result = RegQueryValueEx(hkey, valueName, IntPtr.Zero, ref keyType, null,

     ref length);

    bytes = new byte[Marshal.SizeOf(typeof(uint))];

    length = (uint)bytes.Length;

    keyType = KeyType.None;

    result = RegQueryValueEx(hkey, valueName, IntPtr.Zero, ref keyType, bytes,

     ref length);

    if (ERROR_SUCCESS != result) return result;

    dwordResult = BitConverter.ToUInt32(bytes, 0);

    return ERROR_SUCCESS;

   } finally {

    if (UIntPtr.Zero != hkey) {

     RegCloseKey(hkey);

    }

   }

  }


  ///

  /// Удаляет заданный параметр из раздела реестра

  ///

  /// Имя ключа

  /// Имя параметра

  /// В успешном случае возвращается

  /// ERROR_SUCCESS

  public static int DeleteValue(UIntPtr root, string keyName,

   string valueName) {

   UIntPtr hkey = UIntPtr.Zero;

   try {

    int result = RegOpenKeyEx(root, keyName, 0, KeyAccess.None, ref hkey);

    if (ERROR_SUCCESS != result) return result;

    return RegDeleteValue(hkey, valueName);

   } finally {

    if (UIntPtr.Zero != hkey) {

     RegCloseKey(hkey);

    }

   }

  }


  ///

  /// Типы ключей

  ///

  public enum KeyType : uint {

   None = 0,

   String = 1,

   Binary = 3,

   Dword = 4,

  }


  ///

  /// Тип доступа

  ///

  public enum KeyAccess : uint {

   None = 0x0000,

   QueryValue = 0x0001,

   SetValue = 0x0002,

   CreateSubKey = 0x0004,

   EnumerateSubKeys = 0x0008,

   Notify = 0x0010,

   CreateLink = 0x0020

  }


  ///

  /// HKEY_CLASSES_ROOT

  ///

  public static UIntPtr HKCR = new UintPtr(0x80000000);

  ///

  /// HKEY_CURRENT_USER

  ///

  public static UIntPtr HKCU = new UIntPtr(0x80000001);

  ///

  /// HKEY_LOCAL_MACHINE

  ///

  public static UIntPtr HKLM = new UIntPtr(0x80000002);

  ///

  /// HKEY_USERS

  ///

  public static UIntPtr HKU = new UintPtr(0x80000003);


  ///

  /// Возвращаемое значение в случае успеха

  ///

  public const int ERROR_SUCCESS = 0;


  ///

  /// Функция для создания заданного раздела реестра. Если раздел

  /// уже существует, то функция открывает его.

  ///

  /// [in] Дескриптор к открываемому разделу

  /// или одна из ветвей реестра:

  /// HKCR, HKCU, HKLM.

  /// [in] Имя для нового раздела. Данный

  /// раздел должен быть подразделом раздела, определенного в

  /// параметре hKey.

  ///

  /// [in] Зарезервированный параметр.

  /// Установлен равным 0

  /// [in] Имя класса или типа объекта

  /// Данный параметр игнорируется, если раздел уже существует

  ///

  /// [in] Игнорируется; установите

  /// равным 0

  ///

  /// [in] Игнорируется; установите

  /// равным 0

  ///

  /// [in] Установите в NULL.

  ///

  /// [out] Переменная, получаемая от

  /// дескриптора нового или открытого раздела

  /// Если вы больше не нуждаетесь в дескрипторе, то вызовите

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных