?
Solved

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

Posted on 2005-04-25
2
Medium Priority
?
676 Views
Last Modified: 2013-11-20
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;
}

0
Comment
Question by:KenMac06
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 13859798
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
 

Author Comment

by:KenMac06
ID: 13865726
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question