I have to add a list of sub keys recursively to an item in a Tree control. I am using InsertItem as shown below. I am attaching the path of this element so that i can retrieve when clicked on the tree control.I am able to add the value but not able to retrieve it.
void CMyDlg::FillTreeWithRegistryKeysEx(CString sPath, HTREEITEM hItem)
{
    CString sRegKey = sPath.Left(sPath.Find(_T("\\")));
    sPath = sPath.Mid((sPath.Find(_T("\\")) + 1));
    sPath = CleanRegistryKey(sPath);
    int nKeyCount;
    CString  sSubKey = _T("");
    HKEY handle = GetHkey(sRegKey);
    HTREEITEM hReItem = NULL;
    HKEY phkey;
    std::vector<CString> sSubFolders;
    if (RegOpenKeyEx(handle, sPath, 0, KEY_ALL_ACCESS, &phkey) == ERROR_SUCCESS)
        sSubFolders = EnumRegistryKey(phkey);
    nKeyCount = sSubFolders.size();
    for (int nIndex = 0; nIndex < nKeyCount; nIndex++)
    {
        sSubKey = sPath + _T("\\") +sSubFolders.at(nIndex);
        hReItem = m_cTreeCtrl.InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_STATE, sSubFolders.at(nIndex), 
                                        icoClosedFolder, icoOpenFolder, 0, 0, (LPARAM)(LPCTSTR)sSubKey, hItem, TVI_LAST);
        FillTreeWithRegistryKeys(handle, sSubKey, hReItem);
    }
    RegCloseKey(phkey);
}
While retrieving the string is always blank.
void CMyDlg::OnTvnSelchangedTree(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
    LPARAM lp = pNMTreeView->itemNew.lParam;
    CString sKey = (LPCTSTR)lp;
}
what is going wrong? 
 
     
    