简单的重写了一个CListCtrl类,加了一个这样的函数:int CMyListCtrl::GetCols()
{
int cols[255];
this->GetColumnOrderArray(&cols[0]);
for(int m=0;m<255;m++)
{
if(cols[m]==-858993460)
break;
}
return m;
}
但一运行到this->GetColumnOrderArray(&cols[0]);
就报Unhandled exception in **.exe (MFC42D.DLL):0X00000005:Access Violation   错误        急急!!!!!!

解决方案 »

  1.   

    你是不是还没有添加列(就是列计数是0), 下面是MSDN的示例代码:// Pointer to the list view control.
    CListCtrl* pmyListCtrl;// Reverse the order of the columns in the list view control,
    // that is, make the first column the last, the last column
    // the first, and so on...
    CHeaderCtrl* pHeaderCtrl = pmyListCtrl->GetHeaderCtrl();if (pHeaderCtrl != NULL)
    {
      int nColumnCount = pHeaderCtrl->GetItemCount();
      LPINT pnOrder = (LPINT) malloc(nColumnCount*sizeof(int));
      ASSERT(pnOrder != NULL);  pmyListCtrl->GetColumnOrderArray(pnOrder, nColumnCount);  int i, j, nTemp;
      for (i=0,j=nColumnCount-1;i < j;i++,j--)
      {
         nTemp = pnOrder[j];
         pnOrder[i] = pnOrder[j];
         pnOrder[j] = nTemp;
      }  pmyListCtrl->SetColumnOrderArray(nColumnCount, pnOrder);
      free(pnOrder);
    }Requirements 
      

  2.   

    BOOL GetColumnOrderArray(
       LPINT piArray,
       int iCount = -1 
    );
    Parameters
    piArray 
    A pointer to a buffer that will contain the index values of the columns in the list view control. The buffer must be large enough to contain the total number of columns in the list view control. 
    iCount 
    Number of columns in the list view control. If this parameter is -1, the number of columns is automatically retrieved by the framework. 
    Return Value
    Nonzero if successful; otherwise zero.
      

  3.   

    问题解决了 ygjx007说的也对,主要问题是
    没有建立一个CListCtrl的实例导致错误
    谢谢 楼上 的2位阿