I want to put a small icon at the beginning of each entry of a CListView. Most of the entry data is contained in a wstring matrix, m_wS. In addition, there are two vectors, std::vector<HICON> m_hIcon and std::vector<UINT> m_iIcon which contain the handle and the index of the icon needed to accomplish the task. For reasons not relevant to this discussion, there is an offset of 2 between the matrix and the vectors.


The code to attach the image list to the system image list is executed only once when the application first initializes:
Code:
	m_ImageList.Attach(GetSystemImageListHandle(TRUE));


//..

/// Gets the system's small image list handle which can be attached to a CImageList object
HIMAGELIST  CCabManView::GetSystemImageListHandle( BOOL bSmallIcon )
{
	HIMAGELIST  hSystemImageList; 
	SHFILEINFO    ssfi; 

   if (bSmallIcon)
   {
	hSystemImageList = 
    (HIMAGELIST)SHGetFileInfo( 
    (LPCTSTR)_T("c:\\"), 
     0, 
     &ssfi, 
     sizeof(SHFILEINFO), 
     SHGFI_SYSICONINDEX | SHGFI_SMALLICON); 
   }
   else
   {
		hSystemImageList = 
    (HIMAGELIST)SHGetFileInfo( 
    (LPCTSTR)_T("c:\\"), 
     0, 
     &ssfi, 
     sizeof(SHFILEINFO), 
     SHGFI_SYSICONINDEX | SHGFI_LARGEICON); 
   }
   return hSystemImageList;
}

The code used to fill in the view is fairly standard:
Code:
void CCabManView::OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult)
{
	LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
	CString csValue;
	wchar_t csErr[256];
	UINT nMessageID = 0;
	UINT nMaxError = 256;

	m_pDataset = GetDataSet();
	if(!m_pDataset) return;

	long index = pDispInfo->item.iItem;    
	short subItem = 	pDispInfo->item.iSubItem;
	
	if(pDispInfo->item.mask & LVIF_TEXT)
	{
		try
		{
			index++; //TRACE1("INDEX = %d\n", index);

		}
		catch(CException* e)
		{
			e->ReportError(MB_OK, nMessageID);
			e->Delete();
			return;
		}

		try
		{
			csValue = (wchar_t*)m_wS(index+1, subItem+1).c_str();
		}
		catch(CException* e)
		{
			e->ReportError(MB_OK, nMessageID);
			e->Delete();
			return;
		}

		lstrcpyn(pDispInfo->item.pszText, csValue, pDispInfo->item.cchTextMax);

		if(pDispInfo->item.mask & LVIF_IMAGE)
		{
			TRACE1("index = %d\n", index);
			TRACE2("m_iIcon[%d] = %d\n", index-1, m_iIcon[index-1]);
			TRACE2("m_hIcon[%d] = %d\n", index-1, m_hIcon[index-1]);
			pDispInfo->item.iImage = m_iIcon[index-1];

		}

	}
	

	*pResult = 0;

}// OnLvnGetdispinfo(NMHDR *pNMHDR, LRESULT *pResult)

The icon handles contained in m_hIcon and the icon indexes contained in m_iIcon all check out. But no icon is set into the listview. Clearly, I am missing a step in the process.

I found an example of how to do this in a simpler dialog-based app. Those interested should take a look at:
An ShGetFileInfo Wrapper Class By Doru Cioata 6 Feb 2003
A class built around the use of ShGetFileInfo() function.
http://69.10.233.10/KB/files/cuseshgetfileinfo.aspx

But because my app is an SDI CListView and I have tried to combine additional data using the wstring matrix, the demo code provided by Doru Cioata doesnt seem to work (or I am using it incorrectly). Anyway, attempting to use:
Code:
GetListCtrl().SetIcon(m_hIcon[index-1], FALSE);
or any of it's variants results in a crashed app.

I realize this is a bit of a long harangue, but if anyone can help, I sure would appreciate it. Thanks.