undeclared identifiers: GetCount & GetText not in stdafx.h?

Hi Experts,
I'm trying to adapt some of the code from Prosise (from the Phones example at the end of Ch8). I've transplanted the File handlers from his CChildView into one of mine (generated by the MFC). The compiler is complaining that GetCount & GetText  are undeclared identifiers, although I've got stdafx.h at the top of ChildView.cpp - I've tried adding afx.h and afxwin.h. but that makes no difference.

The MSDN help is only of help in how to use the function, not how to resolve references to it.
 
Any ideas?

BOOL CChildView::SaveFile(LPCTSTR pszFile)
{
    BOOL bResult = FALSE;

     try {
          CStdioFile file (pszFile, CFile::modeWrite | CFile::modeCreate);
          DWORD dwCount = GetCount (); // error C2065: 'GetCount' : undeclared identifier
          file.Write (&dwCount, sizeof (dwCount));
          if (dwCount) {
               for (int i=0; i<(int) dwCount; i++) {
                    CString string;
                    GetText (i, string); // similar error C2065: 'GetText' : undeclared identifier
                    string += _T ("\n");
                    file.WriteString (string);
               }
          }
          bResult = TRUE;
     }
     catch (CFileException* e) {
          e->ReportError ();
          e->Delete ();
     }

  return bResult;
}

KenMac06Asked:
Who is Participating?
 
jkrCommented:
It seems you are referring to a list box that is a member of you view class. Then, that should be

     try {
         CStdioFile file (pszFile, CFile::modeWrite | CFile::modeCreate);
         DWORD dwCount = m_listbox.GetCount ();
         file.Write (&dwCount, sizeof (dwCount));
         if (dwCount) {
              for (int i=0; i<(int) dwCount; i++) {
                   CString string;
                   m_listbox.GetText (i, string);
                   string += _T ("\n");
                   file.WriteString (string);
              }
         }
         bResult = TRUE;
    }

0
 
KenMac06Author Commented:
Thanks - your answer put me onto the right track, and now I understand the problem:

I had moved this function ifrom CChildView nto CMainFrame to resolve other variables, so GetCount & GetText were out of the scope of the listbox. Worse still, the listbox doesn't exist in the new app that I've transplanted these functions into, so I'd better go and add one!..or some other control that I can harvest dummy strings from, in order to try things out.

Rgds,

Ken.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.