RegSetValue

3.1

  #include <shellapi.h>    

  LONG RegSetValue(hkey, lpszSubKey, fdwType, lpszValue, cb)    
  HKEY hkey; /* handle of key, */  
  LPCSTR lpszSubKey; /* address of string for subkey */
  DWORD fdwType; /* must be REG_SZ, */  
  LPCSTR lpszValue; /* address of string for key */
  DWORD cb; /* ignored */

The RegSetValue function associates a text string with a specified key.

Parameters

hkey

Identifies a currently open key (which can be HKEY_CLASSES_ROOT). This value should not be NULL.

lpszSubKey

Points to a null-terminated string specifying the subkey of the hkey parameter with which a text string is associated. If this parameter is NULL or points to an empty string, the function sets the value of the hkey parameter.

fdwType

Specifies the string type. For Windows version 3.1, this value must be REG_SZ.

lpszValue

Points to a null-terminated string specifying the text string to set for the given key.

cb

Specifies the size, in bytes, of the string pointed to by the lpszValue parameter. For Windows version 3.1, this value is ignored.

Return Value

The return value is ERROR_SUCCESS if the function is successful. Otherwise, it is an error value.

Comments

If the key specified by the lpszSubKey parameter does not exist, the RegSetValue function creates it.

Example

The following example uses the RegSetValue function to register a filename extension and its associated class name:

RegSetValue(HKEY_CLASSES_ROOT,  /* root                            */
    ".XXX",                     /* string for filename extension   */
    REG_SZ,                     /* required                        */
    "NewAppDocument",           /* class name for extension        */
    14);                        /* size of text string             */

RegSetValue(HKEY_CLASSES_ROOT,  /* root                            */
    "NewAppDocument",           /* string for class-definition key */
    REG_SZ,                     /* required                        */
    "New Application",          /* text description of class       */
    15);                        /* size of text string             */

See Also

RegCreateKey, RegQueryValue