Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6033477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:29:19+00:00 2026-05-23T05:29:19+00:00

Language: Visual C++, MFC Environment: Visual Studio 2005 So I posted a similar question,

  • 0

Language: Visual C++, MFC

Environment: Visual Studio 2005

So I posted a similar question, but I’ve come to realize that I was asking the wrong question. I’m trying to use a loop to call a function on several different variables, but somewhere along the way, the program is crashing.

Simplified code is below, but I think it’s actually easier to just explain it. I have a function that takes in a CString as a parameter. I have several variables I wish to feed to this function, so I put their names into an array, and I’m trying to pass them to the function that way.

// THE CODE BELOW IS WHAT I HAVE, BUT IT DOES NOT WORK //

Header File:

CString m_strTop;
CString m_strLeft;
CString m_strRight;
CString m_strBottom;

CString *var[4];

Source File:
Constructor()

CString *var[4] = {
  &m_strTop
, &m_strLeft
, &m_strRight
, &m_strBottom
};

Source File:
theFunction()

void myClass::DoDataExchange(CDataExchange* pDX)
{
   CSAPrefsSubDlg::DoDataExchange(pDX);

   for(int i = 2001, j = 0; i <= 2004; i++, j++)
   {
       // THE LINE BELOW IS WHERE THINGS GO WONKY, SPECIFICALLY AT &var[j]
       DDX_Text(pDX, i, *var[j]); // 'i' is the ID of the textbox
   }
} 

— What DDX_Text expects —

void AFXAPI DDX_Text(
   CDataExchange* pDX,
   int nIDC,
   CString& value 
);

So like I said, I just need to feed the function the actual name of the variable. At least I think. What it’s actually doing is establishing a connection between a text box in a dialog and the variable where the text box’s input will be stored. I’m dereferencing correctly and everything, but I don’t think this is the right approach.

Thank you for any help. And to people who answered my previous question, my apologies for misrepresenting the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:29:20+00:00Added an answer on May 23, 2026 at 5:29 am

    var is an array of pointers to CString.
    var[j] is a pointer to CString.
    &var[j] is a pointer to pointer to CString.

    Now you need to pass the CString object. So you need:

    DDX_Text(pDX, i, *var[j]); // dereference a pointer to CString.
    

    Consider using std::vector instead of the C-array. It would be:

    std::vector<CString> var(4);
    ...
    
    DDX_Text(pDX, i, var[j]); // pass a CString object
    

    I’ve noted that you’re declaring variable var once again in the constructor:

    CString *var[4] = { // this declares new temporary variable, 
                        // it doesn't initialize one from the header file
      &m_strTop
    , &m_strLeft
    , &m_strRight
    , &m_strBottom
    };
    

    Shouldn’t it be? :

    var[0] = &m_strTop;
    var[1] = &m_strLeft;
    var[2] = &m_strRight;
    var[3] = &m_strBottom;
    

    I suppose you need the following:

    // header file
    class myClass
    {
      std::vector<CString> var_;
      ...
    };
    
    // source file
    myClass::myClass() : var_(4)
    {
       ...
    }
    
    void myClass::theFunction(CDataExchange* pDX)
    {
       CSAPrefsSubDlg::DoDataExchange(pDX);
    
       for(int i = 2001, j = 0; i <= 2004; i++, j++)
       {
           DDX_Text(pDX, i, var_[j]); // 'i' is the ID of the textbox
       }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Language: Visual C++, MFC Environment: Visual Studio 2005 I have a dialog that requires
While I realize that Visual C++ is a language lacking much of the syntactic-sugar
Language : C++ Development Environment : Microsoft Visual C++ Libraries Used : MFC Problem
Good afternoon, I've created a visual studio package that registers the Verilog language as
IDE: Microsoft Visual Studio Professional 2008 Language: C# Background: I have one form and
C#3 (Visual Studio 2008) introduced a breaking change to the language ( http://msdn.microsoft.com/en-us/library/cc713578.aspx ,
I'm working on Visual Studio Extensibility and I need to set the shell language
I'm new to it and currently using the visual flow-chart like language that the
Visual Studio language extensibility Does anybody know whether there's an open source (or paid)
I want enchanted syntax coloring in comments for C++ language in Visual Studio 2010.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.