第二个问题:
首先使用RegCreateKeyEx创建一个key,
然后用RegSetValueEx设置值,
二进制值   dwType = REG_BINARY
DWORD值   dwType = REG_DWORD删除一个值使用RegDeleteValue详细参照MSDN的Platform SDK: Registry

解决方案 »

  1.   

    补充,
    字符串值   dwType = REG_SZ
      

  2.   

    楼上的朋友说的删除部分不能在Win2000下使用:
    删除
    void DeleteRegistryKey(HKEY hKeyRoot,char *szSubKey)
    {
    LONG lErr;
    HKEY hkey = NULL;
    //Open the key check sub-keys
    lErr = RegOpenKeyEx(hKeyRoot,szSubKey,NULL,KEY_ALL_ACCESS,&hkey);
    if(lErr==ERROR_SUCCESS) {
    FILETIME ftKey;
    char achName[MAX_PATH];
    DWORD dwcbName;
    DWORD dwiKey=0;
    //check for subkeys to delete
    while(lErr==ERROR_SUCCESS) {
    dwcbName = sizeof(achName);
    lErr=RegEnumKeyEx(hkey,dwiKey,achName,&dwcbName,0,NULL,NULL,&ftKey);
    if(lErr==ERROR_SUCCESS) {
    DeleteRegistryKey(hkey,achName);
    // ++dwiKey;
    }
    }
    //close the subkey and try to delete it
    RegCloseKey(hkey);
    lErr = RegDeleteKey(hKeyRoot,szSubKey);
    if(lErr!=ERROR_SUCCESS) {
    char *szBuf,*szTitle;
    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|
      FORMAT_MESSAGE_IGNORE_INSERTS|
      FORMAT_MESSAGE_FROM_SYSTEM,
      NULL,
      0,
      lErr,
      (LPTSTR)&szBuf,
      1,
      NULL);
    szTitle=new char[512];
    sprintf(szTitle,"Unable to delete registry key %s",szBuf);
    MessageBox(NULL,szBuf,szTitle,MB_OK);
    delete szTitle;
    LocalFree(szBuf);
    }
    }
    }
    添加
    BOOL CRegistry::SetEntry(const int majorKey,
     const CString& subKey,
     const CString& value)
    {
    HKEY hMajorKey = 0;
    switch (majorKey)
    {
    case CREGISTRY_SYSTEM:
    {
    hMajorKey = HKEY_CLASSES_ROOT;
    break;
    }
    case CREGISTRY_USER:
    {
    hMajorKey = HKEY_CURRENT_USER;
    break;
    }
    case CREGISTRY_MACHINE:
    {
    hMajorKey = HKEY_LOCAL_MACHINE;
    break;
    }
    default:
    return FALSE; } CString actualKey, name;
    SplitKeyName(subKey, actualKey, name); HKEY hKey = 0;
    long ret = ::RegOpenKeyEx(hMajorKey, (const char *) actualKey,
    0, KEY_ALL_ACCESS, & hKey); if (ret != ERROR_SUCCESS)
    {
    // Create key
    char classType[1];
    classType[0] = 0;
    DWORD disposition = 0;
    ret = ::RegCreateKeyEx(hMajorKey, (const char *) actualKey,
    0, classType, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
    & hKey, & disposition); if (ret != ERROR_SUCCESS)
    return FALSE;
    } DWORD reserved = 0;
    DWORD type = REG_SZ;
    BYTE *buf = new BYTE[value.GetLength() + 1];
    strcpy((char *)buf, (const char *) value);
    DWORD sz = value.GetLength() + 1;
    ret = ::RegSetValueEx(hKey, (const char *) name, reserved, type, buf, sz);
    delete[] buf;

    ::RegCloseKey(hKey);

    if (ret == ERROR_SUCCESS)
    {
    return TRUE;
    }
    else
    return FALSE;
    }
      

  3.   

    LONG RegCreateKeyEx(
      HKEY hKey,                                  // handle to open key
      LPCTSTR lpSubKey,                           // subkey name
      DWORD Reserved,                             // reserved
      LPTSTR lpClass,                             // class string
      DWORD dwOptions,                            // special options
      REGSAM samDesired,                          // desired security access
      LPSECURITY_ATTRIBUTES lpSecurityAttributes, // inheritance
      PHKEY phkResult,                            // key handle 
      LPDWORD lpdwDisposition                     // disposition value buffer
    );PHKEY phkResult,这个参数应该写什么?
      

  4.   

    想一想,你要把打开的键放在那?OK!对了就是放你刚定义的HKEY
    HKEY m_mykey;
    RegCreateKeyEx(
      HKEY hKey,                                  // handle to open key
      LPCTSTR lpSubKey,                           // subkey name
      DWORD Reserved,                             // reserved
      LPTSTR lpClass,                             // class string
      DWORD dwOptions,                            // special options
      REGSAM samDesired,                          // desired security access
      LPSECURITY_ATTRIBUTES lpSecurityAttributes, // inheritance
      PHKEY &m_mykey,                            // 在这呢!
      LPDWORD lpdwDisposition                     // disposition value buffer
    );
      

  5.   

    RegCreateKeyEx(HKEY_CURRENT_USER,"\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"
    ,0,"aa",REG_OPTION_NON_VOLATILE,KEY_CREATE_SUB_KEY,
    NULL,&mHkey,REG_CREATED_NEW_KEY);
     error C2664: 'RegCreateKeyExA' : cannot convert parameter 9 from 'const long' to 'unsigned long *'按照MSDN写的,为什么有错误?
      

  6.   

    第九个参数你用了DWORD,但要求的是 const long型的!
      

  7.   

    HKEY m_key;
    DWORD m_dwDispoistion, m_dwLength, m_dwType, m_dwRdLen;
    int m_nError;
    CString m_strKeyPath;
    m_strKeyPath.Format("Software\\123\\789");
    m_nError=RegCreateKeyEx(HKEY_CURRENT_USER, m_strKeyPath, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &m_key, &m_dwDispoistion);
    在错我就没法了.
      

  8.   

    SORRY,编译没有错误,可是不能创建键值
      

  9.   

    D:\FILES\VC++\Registry\Registry.cpp(60) : warning C4101: 'm_dwType' : unreferenced local variable
    D:\FILES\VC++\Registry\Registry.cpp(59) : warning C4101: 'm_dwLength' : unreferenced local variable
    D:\FILES\VC++\Registry\Registry.cpp(61) : warning C4101: 'm_dwRdLen' : unreferenced local variable
      

  10.   

    Sorry 要不你新建个对话框试一下把,我的是一写一个准
      

  11.   

    (HKEY_CURRENT_USER, m_strKeyPath, NULL, "aa",//这里改成字符就没有错,//可是不能创建
     REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &m_key, &m_dwDispoistion);
      

  12.   

    RegSetValueEx
    怎么用也教教我吧
      

  13.   

    REG_OPTION_NON_VOLATILE也许不对,因为我是在window2000下,试一试
    REG_OPTION_NON_VOLATILE 和 REG_OPTION_BACKUP_RESTORE 
      

  14.   

    哎!帮人帮到底,送佛送到西,不过要是你不给分我就&#$@!
    DWORD m_l;
    DWORD m_dwLength;
    m_dwLength=4;
    m_l=123;
    m_nError=RegSetValueEx( m_key, _T("HelloWorld"), NULL, REG_DWORD, (BYTE*)&m_l, m_dwLength);
      

  15.   

    那就好,字符串就把REG_DWORD 换成 REG_SZ 二进制就 REG_BINARY不过长度要小心是字节数