How to make Function with return type CList And read that List in Calling function?

StackOverflow https://stackoverflow.com/questions/22904302

  •  28-06-2023
  •  | 
  •  

Question

CList Get_StartUp_Programs(CString csRegistryPath)

{

CList<CString,CString> listData;
HKEY hKey;      

        if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,csRegistryPath,0,KEY_ALL_ACCESS | KEY_WOW64_64KEY,&hKey) == ERROR_SUCCESS)
        {       

        DWORD dwValues, dwMaxValueNameLen, dwMaxValueLen;

        LONG lRet = ::RegQueryInfoKey(hKey, 
                          NULL, NULL,    // lpClass, lpcClass
                          NULL,          // lpReserved
                          NULL, NULL,    // lpcSubKeys, lpcMaxSubKeyLen
                          NULL,          // lpcMaxClassLen
                          &dwValues,
                          &dwMaxValueNameLen,
                          &dwMaxValueLen,
                          NULL,          // lpcbSecurityDescriptor
                          NULL);         // lpftLastWriteTime 

        if(ERROR_SUCCESS == lRet)
        {  

            LPTSTR pszName = new TCHAR[dwMaxValueNameLen + 1];
            LPBYTE lpData   = new BYTE[dwMaxValueLen];
            for(DWORD dwIndex = 0; dwIndex < dwValues; dwIndex++)
            {
                DWORD dwNameSize  = dwMaxValueNameLen + 1;
                DWORD dwValueSize = dwMaxValueLen;
                DWORD dwType;
                lRet = ::RegEnumValue(hKey, dwIndex, pszName, &dwNameSize,0, &dwType, lpData, &dwValueSize);
                CString strName = pszName;
                listData.AddHead(strName);                  
            CLog::Log(strName + _T(""));
            }
        delete []pszName;
        delete []lpData;
        }
        }

}

in this function i want list of start up programs returned by this function so that i can process that list in calling function. How can i return list of Start up programs

Was it helpful?

Solution

CList has no copy constructor and no copy Operator. So the easiest way is to pass an CList object as a reference to the function.

void FunctionToGetListData(CList<CString,CString> &listData)
{
  listData.RemobveAll();
...

Call the function just in using the list as an argument:

CList<CString,CString> listData;
FunctionToGetListData(listData);

Or use std:list. you can easily return a std::list from a function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top