if(RegOpenKeyEx(hkHandle, szKey, 0, KEY_READ, &hkHandle) != ERROR_SUCCESS)
if(RegOpenKeyEx(ugUninstall.hWrMainRoot, szKey, 0, KEY_READ, &hkResult) != ERROR_SUCCESS)
DWORD CleanupAppList(){  typedef struct siAppListStruct siAppList;  struct siAppListStruct  {    char szAppID[MAX_BUF];    siAppList *Next;  };  siAppList *siALHead;  siAppList *siALPrev;  siAppList *siALTmp;  char      *szRv = NULL;  char      szKey[MAX_BUF];  char      szBuf[MAX_BUF];  char      szDefaultApp[MAX_BUF_TINY];  BOOL      bFoundDefaultApp;  HKEY      hkHandle;  DWORD     dwIndex;  DWORD     dwBufSize;  DWORD     dwTotalSubKeys;  DWORD     dwTotalValues;  DWORD     dwAppCount;  FILETIME  ftLastWriteFileTime;  GetPrivateProfileString("General", "Default AppID", "", szDefaultApp, MAX_BUF_TINY, szFileIniUninstall);  hkHandle = ugUninstall.hWrMainRoot;  wsprintf(szKey, "%s\\%s\\AppList", ugUninstall.szWrMainKey, ugUninstall.szUserAgent);  if(RegOpenKeyEx(hkHandle, szKey, 0, KEY_READ, &hkHandle) != ERROR_SUCCESS)  {    return(0);  }  siALHead = NULL;  dwAppCount = 0;  dwTotalSubKeys = 0;  dwTotalValues  = 0;  RegQueryInfoKey(hkHandle, NULL, NULL, NULL, &dwTotalSubKeys, NULL, NULL, &dwTotalValues, NULL, NULL, NULL, NULL);  for(dwIndex = 0; dwIndex < dwTotalSubKeys; dwIndex++)  {    dwBufSize = sizeof(szBuf);    if(RegEnumKeyEx(hkHandle, dwIndex, szBuf, &dwBufSize, NULL, NULL, NULL, &ftLastWriteFileTime) == ERROR_SUCCESS)    {      if((siALTmp = NS_GlobalAlloc(sizeof(struct siAppListStruct))) == NULL)        exit(1);      lstrcpy(siALTmp->szAppID, szBuf);      siALTmp->Next = NULL;      if(siALHead == NULL)        siALHead = siALTmp; //New list, point the head at it.      else        siALPrev->Next = siALTmp;      siALPrev = siALTmp;    }  }  siALTmp = siALHead;  while(siALTmp != NULL)  {    if(lstrcmpi(siALTmp->szAppID, szDefaultApp) == 0)      bFoundDefaultApp = TRUE;    // ProcessAppItem returns the # of installations of the App    dwAppCount = dwAppCount + ProcessAppItem(ugUninstall.hWrMainRoot, szKey, siALTmp->szAppID);    siALPrev = siALTmp;    siALTmp = siALTmp->Next;    FreeMemory(&siALPrev);  }  if(dwAppCount == 0)    RegDeleteKey(ugUninstall.hWrMainRoot, szKey);  // If the Default App is not listed in AppList, then the shared app should not be in the   //   Windows Add/Remove Programs list either.  if(!bFoundDefaultApp)  {    wsprintf(szKey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\%s (%s)",ugUninstall.szProductName, ugUninstall.szUserAgent);    RegDeleteKey(ugUninstall.hWrMainRoot, szKey);  }  return(dwAppCount);}