检查注册表项是否存在,该怎么解决

检查注册表项是否存在
HKEY   hKey;
HKEY   hKey2;
LPCTSTR   StrKey= "Software\\Microsoft\\Windows\\CurrentVersion\\Run ";
long   ll;
ll   =   ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,StrKey,NULL,KEY_ALL_ACCESS,&hKey);
if(ERROR_SUCCESS   ==   ll   )
{
ll   =   ::RegOpenKey(hKey, "GGG ",&hKey2);
//ll   =   ::RegDeleteValue(hKey, "GGG ");
if(ERROR_SUCCESS   ==   ll   )
m_AutoRun.SetCheck(1);
}
::RegCloseKey(hKey);
::RegCloseKey(hKey2);

删除都正常,为什么GGG项本身存在就是返回2,意思说ERROR_FILE_NOT_FOUND

------解决方案--------------------
GGG is a key or value?
------解决方案--------------------
int GetRegValue(char *subkey, char *keyname, char *keyvalue, HKEY hKeyIn)
{
ULONG regsize = 0;
HKEY hKeyOut;
LPBYTE pValue;

if( ERROR_SUCCESS != RegOpenKeyEx(hKeyIn, subkey, 0, KEY_CREATE_LINK | KEY_WRITE | KEY_READ | KEY_NOTIFY, &hKeyOut))
{
return -1;
}
if(ERROR_SUCCESS != RegQueryValueEx(hKeyOut, keyname, NULL, NULL, NULL, &regsize))
{
return -1;
}
pValue = (LPBYTE)malloc(regsize);
memset(pValue, 0x00, regsize);
if(ERROR_SUCCESS != RegQueryValueEx(hKeyOut, keyname, NULL, NULL, pValue, &regsize))
{
return -1;
}

strcpy(keyvalue, (char *)pValue);
free(pValue);
pValue = NULL;
RegCloseKey(hKeyOut);

return 0;
}