我没有用过这个函数找到MSDN的解释是这样的:
The key that the RegCreateKeyEx function creates has no values. An application can use the RegSetValue or RegSetValueEx function to set key values. The key identified by the hKey parameter(即第一个参数) must have been opened with KEY_CREATE_SUB_KEY access. To open the key, use the RegCreateKeyEx or RegOpenKeyEx function. An application cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. An application can create subkeys in lower levels of the HKEY_USERS or HKEY_LOCAL_MACHINE trees.

解决方案 »

  1.   

    参数不对吧,下面是一个调用的例子:
    HKEY hLocKey;
    DWORD dwDisposition;
    LPCTSTR lpSubKeyName = _T("WebCenter");
    LPTSTR lpClass = _T("String");
    LONG lResult;
    lResult = RegCreateKeyEx(HKEY_CURRENT_USER,lpSubKeyName,0,lpClass,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hLocation,&dwDisposition);
    其实关键是你没有为最后两个参数分配有效内存,函数用这两个参数的地址返回得到的子键句柄和操作方法值,应该传给一个已分配的指针。